|
本帖最后由 sbansar 于 2022-12-2 09:39 编辑
附件已经上传
没找到问题在哪里,找出来替换的不是想要的数据,求助大神
代码
Sub test()
'需求:补上A3~C3,A11~C11,A13~C13的省市数据
'将地址替换成店名
lastrow = Worksheets("源").Cells(Rows.Count, 1).End(xlUp).Row
Dim data, dic, i&
data = Worksheets("字典").UsedRange.Value
Set dic = CreateObject("Scripting.Dictionary")
'替换地址
For i = 1 To UBound(data)
dic(data(i, 4)) = data(i, 2)
Next i
data = Worksheets("源").UsedRange.Value
For i = 1 To UBound(data)
If dic.exists(data(i, 1)) Then data(i, 1) = dic(data(i, 2))
Next i
With Worksheets("源").Range("d2:d" & lastrow)
.NumberFormat = "@"
.Value = data
End With
Set dic = Nothing
End Sub
|
|