简体   繁体   English

仅将单元格中的某些字符与另一个单元格中的某些字符进行比较

[英]Compare only some characters in a cell to only some characters in another cell

Hi guys I am running a macro in Excel 2003 to match property addresses to their owners addresses so I end up with a report of absentee owners. 嗨,大家好我在Excel 2003中运行一个宏来匹配属性地址和它们的所有者地址,所以我最终得到了一个缺席所有者的报告。

So in: 所以在:

column A                                       column C 
10 Smith DR Smithville                         10 Smith DVE, Smithfield, 49089 Antartica 

This is how some of the raw data has been input but I need for this record and all the other slightly different records to be a match and therefore not selected by the macro as it searches for absentee owners addresses then populates the selected records to sheet2. 这是一些原始数据的输入方式,但我需要这个记录和所有其他略有不同的记录匹配,因此宏不会选择它,因为它搜索缺席所有者地址然后将所选记录填充到sheet2。 In laymans terms if I could compare say only the first 6 characters in column A to the first 6 characters in column C then I think it would work the way I need it to. 在外行人的术语中,如果我可以比较只说A列中的前6个字符和C列中的前6个字符,那么我认为它将按我需要的方式工作。

Does anyone know how I can achieve this within my macro shown below 有谁知道如何在我的宏中显示如下所示

Sub test()
Dim i As Long, lr As Long, r As Long, ws As Worksheet, value As Variant, 
    val As Variant
Dim sval As Integer, lr2 As Long
Application.ScreenUpdating = False
Set ws = Worksheets("Sheet1")
lr = ws.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To lr
    value = Split(Cells(i, 1).value, ", ")
    For val = LBound(value) To UBound(value)
        sval = InStr(1, Cells(i, 3).value, value(val), 1)
        If sval = 0 Then Range("A" & i & ":" & "C" & i).Interior.Color = 65535
    Next
Next
For r = 2 To lr
    lr2 = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
    If Range("A" & r).Interior.Color = 65535 Then
        Rows(r).Copy Destination:=Sheets("Sheet2").Rows(lr2 + 1)
        lr2 = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
    End If
Next r
Sheets("Sheet2").Cells.Interior.ColorIndex = 0
Application.ScreenUpdating = True
MsgBox "Done Macro"
End Sub

Hopefully I have pasted the code in the correct format required here. 希望我已经以这里所需的正确格式粘贴代码。 So any help and guidance would be much appreciated. 因此,非常感谢任何帮助和指导。

You can use the formula LEFT() . 您可以使用公式LEFT() This will check the first 6 characters from the cell in column A to the first 6 characters in column C. If there's a match, it will add the value from column A to the next free cell in column A, Sheet2. 这将检查A列中单元格中的前6个字符到C列中的前6个字符。如果匹配,它会将A列中的值添加到A列Sheet2中的下一个空闲单元格。

Sub First6Characters()

LastRow = Cells(Rows.Count, "A").End(xlUp).Row
LastRowSheet2 = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row

For i = 1 To LastRow
    If Left(Range("A" & i), 6) = Left(Range("C" & i), 6) Then
        Sheets("Sheet2").Range("A" & LastRowSheet2).Value = Range("A" & i).Value
        LastRowSheet2 = LastRowSheet2 + 1
    End If
Next i

End Sub

Source: http://www.techonthenet.com/excel/formulas/left.php 资料来源: http //www.techonthenet.com/excel/formulas/left.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我希望一个单元格显示另一个单元格中的某些字符 - I want one cell to display some of the characters from another cell 仅将文本从一个字符单元移动到另一个字符单元 - Moving ONLY text over from one cell of characters to another 如何从具有 VBA 的单元格中获取一些字符 - How can I get some characters from a cell with VBA 如果单元格以 __extract 前 3 个字符开头。 如果以 __ 开头,则只提取 2 - If cell starts with__extract first 3 characters. If it starts with __ only extract 2 如何使 Excel 单元格中的最后 3 个字符可见 - How to make visible only last 3 characters from Excel cell 让一个单元格仅显示键入的文本的后8个字符 - Having a cell show only the last 8 characters of the text typed in 使用单元格内容但仅前6个字符的excel超链接 - excel hyperlink using cell content but only the first 6 characters VBA查找单元格中的数字,字母和字符以及仅用数字/字母替换单元格的内容 - VBA Finding Numbers, Letters, and Characters in Cell and Replacing Content of Cell With Only Numbers/Letters Excel:get_Range(cellName).Text 仅给出单元格中的 8000 个字符。 这里 Cell 总共有 20000 个字符 - Excel : get_Range(cellName).Text gives only 8000 characters from cell. Here Cell has total 20000 characters Excel公式:查找一个单元格中的所有字符是否都在另一个单元格中,即使在另一个单元格中它们是更多字符 - Excel FORMULA: Find if all the characters in a cell are in another cell even if in this another cell they are more characters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM