|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 按钮2_Click()
Set d = CreateObject("scripting.dictionary")
r = Sheets("汇总表").Cells(Rows.Count, 2).End(3).Row
arr = Sheets("汇总表").[a1].Resize(r, 4)
ptn = ""
For j = 2 To UBound(arr)
If Len(arr(j, 3)) > 0 Then
d(arr(j, 2) & arr(j, 3)) = arr(j, 4)
ptn = ptn & "|" & arr(j, 3)
End If
Next j
arr = Sheets("明细表").UsedRange
With CreateObject("vbscript.regexp")
.Pattern = Mid(ptn, 2)
For j = 2 To UBound(arr)
If .test(arr(j, 9)) Then
m = .Execute(arr(j, 9))(0).Value
str1 = arr(j, 8) & m
If d.exists(str1) Then
arr(j, 9) = Replace(arr(j, 9), m, "【" & d(str1) & "】")
End If
End If
Next
End With
Sheets("明细表").UsedRange = arr
End Sub
|
|