本帖最后由 吴虾咪 于 2022-11-8 08:17 编辑
省份如里查找的词前面有空行就替换不出来,像云南这个前面有空行就替换不出来。还有云南-廊坊要是在二佰多行替换不了,也会出现错误。
Private Sub CommandButton1_Click()
Dim arr(), brr, x%, y%, m%, i%
brr = Range("A1:B1000").CurrentRegion
ReDim arr(1 To UBound(brr, 1) - 2, 1 To 1)
x = 2
For i = 1 To 2
Do
x = x + 1
For y = 3 To UBound(brr, 1)
brr(y, 3) = VBA.Replace(brr(y, 3), brr(x, i), brr(2, i + 3))
Next y
Loop Until brr(x, 1) = ""
x = 2
Next i
For y = 1 To UBound(arr, 1)
arr(y, 1) = brr(y + 2, 3)
Next y
Range("F3").Resize(UBound(arr, 1), 1) = arr
End Sub
|