我有街道名称和地址列表。现在我想查找地址列中是否有与街道名称匹配的值,然后返回街道名称。
答案 0 :(得分:0)
假设地址在A1:
中For AddressRow = FirstRow To LastRow
address = Cells(AddressRow,1)
For StreetRow = FirstRow To LastRow
If "*" & Cells(StreetRow,3) & "*" Like address Then MsgBox Cells(StreetRow,3)
Next
Next
我希望您可以定义FirstRow,LastRow并知道您希望输出现在转到消息框的位置。
答案 1 :(得分:0)
假设地址列为A
Street_name列为C
。这段代码不是最优雅但有效。
Private Sub DoTheJob()
Dim intRowStreetName As Integer
Dim intRowAdress As Integer
intRowStreetName = 1
intRowAdress = 1
strPartOfStreetName = "nguyen"
With Worksheets("Sheet1")
Do While .Cells(intRowStreetName, 3).Value <> Empty
intRowAdress = 1
If InStr(1, .Cells(intRowStreetName, 3).Value, strPartOfStreetName, vbTextCompare) > 0 Then
Do While .Cells(intRowAdress, 1).Value <> Empty
If InStr(1, .Cells(intRowAdress, 1).Value, .Cells(intRowStreetName, 3).Value, vbTextCompare) > 0 Then
.Cells(intRowAdress, 2).Value = .Cells(intRowStreetName, 3).Value
End If
intRowAdress = intRowAdress + 1
Loop
End If
intRowStreetName = intRowStreetName + 1
Loop
End With
End Sub