比较输出不匹配地址的 Excel VBA 地址



我正在处理一个有三个选项卡的工作簿。我的客户列表地址、外包客户列表地址:和输出不匹配:。 我希望运行我的列表代理一个外包列表,如果我的地址列表与源列表中的任何地址都不匹配。 它在"无匹配"选项卡上输出。

我已经建立了一个工作文档,但它太慢了,感觉这里有人真的可以帮助我指出正确的方向。

所有三张纸列标题("客户名称"、"地址 1"、"地址 2"、"城市"、"州"、"邮政编码"(

我正在使用类似于下面的代码来查找所有列上没有匹配项的代码。它只看前几个字符,希望加快速度,但我没有得到任何速度。

我正在一个有点像这样的循环上运行它,在比较地址代理 200,000 条记录时,它似乎非常连续和缓慢。

For I = 2 To LastRow
If Left(UCase(Trim(wsAddressS_1.Cells(1 + I, 6).Value)), 5) = 
Left(UCase(VLookLike(wsAddressS_1.Cells(1 + I, 6).Value, wsAddressS_2.Range("F1:F" & LastRow2 + 10))), 5) Then
Match_Zip = "Match"
Else
Match_Zip = "No Match"
End If
If strMatchZip <> "Match" Then
LastRow1 = wsAddressS_4.Range("F" & Rows.Count).End(xlUp).Row
wsAddressS_4.Cells(LastRow4 + 1, 1).Value = wsAddressS_1.Cells(1 + I, 1).Value
wsAddressS_4.Cells(LastRow4 + 1, 2).Value = wsAddressS_1.Cells(1 + I, 2).Value
wsAddressS_4.Cells(LastRow4 + 1, 3).Value = wsAddressS_1.Cells(1 + I, 3).Value
wsAddressS_4.Cells(LastRow4 + 1, 4).Value = wsAddressS_1.Cells(1 + I, 4).Value
wsAddressS_4.Cells(LastRow4 + 1, 5).Value = wsAddressS_1.Cells(1 + I, 5).Value
wsAddressS_4.Cells(LastRow4 + 1, 6).Value = wsAddressS_1.Cells(1 + I, 6).Value
End If
Sleep 10
DoEvents
Next I

例如 VLookLike

Private Function VLookLike(txt As String, rng As Range) As String
Dim temp As String, e, n As Long, a()
Static RegX As Object
If RegX Is Nothing Then
Set RegX = CreateObject("VBScript.RegExp")
With RegX
.Global = True
.IgnoreCase = True
.Pattern = "(S+).*" & Chr(2) & ".*1"
End With
End If
With RegX
For Each e In rng.Value
If UCase$(e) = UCase(txt) Then
VLookLike = e
Exit For
End If
temp = Join$(Array(e, txt), Chr(2))
If .test(temp) Then
n = n + 1
ReDim Preserve a(1 To 2, 1 To n)
a(2, n) = e
Do While .test(temp)
a(1, n) = a(1, n) + Len(.Execute(temp)(0).submatches(0))
temp = Replace(temp, .Execute(temp)(0).submatches(0), "")
Loop
End If
Next
End With
If (VLookLike = "") * (n > 0) Then
With Application
VLookLike = .HLookup(.Max(.Index(a, 1, 0)), a, 2, False)
End With
End If
End Function

任何帮助或建议将不胜感激!

抱歉,我没有阅读所有代码,但是我在比较字符串时遇到了问题。如果您告诉 vba 您将比较 2 个字符串,也许它会起作用。例如,您可以使用函数 Cstr((

CStr(Left(UCase(StrAddress), 3)) = CStr(Left(UCase(VLookLike(StrAddress, rng2)), 3))