当我运行这个宏时没有任何反应,它不会附加地址表的城市列。但宏执行没有错误。
我希望当将数据与地址“城市名称”进行比较时,它会更新相应的“城市”列。我的宏:
Sub UpdateCityNames()
Dim wsLugar As Worksheet
Dim wsSiudad As Worksheet
Dim lastRowLugar As Long
Dim lastRowSiudad As Long
Dim i As Long, j As Long
Dim townOrCityName As String
' Set the worksheets
Set wsLugar = ThisWorkbook.Sheets("Lugar")
Set wsSiudad = ThisWorkbook.Sheets("Siudad")
' Find the last row with data in the Siudad and Lugar sheets
lastRowLugar = wsLugar.Cells(wsLugar.Rows.Count, "H").End(xlUp).Row
lastRowSiudad = wsSiudad.Cells(wsSiudad.Rows.Count, "A").End(xlUp).Row
' Loop through each row in Siudad sheet
For i = 1 To lastRowSiudad
townOrCityName = wsSiudad.Cells(i, 1).Value ' Town or city name
' Loop through each row in Lugar sheet
For j = 1 To lastRowLugar
' Check if the town/city name exists in the address column
If InStr(1, wsLugar.Cells(j, 1).Value, townOrCityName, vbTextCompare) > 0 Then
' Append town/city name to the city column
wsLugar.Cells(j, 2).Value = townOrCityName
End If
Next j
Next i
End Sub