|
|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
借楼学习一下字典和正则表达式
Sub test()
Application.ScreenUpdating = False
arr = [a1].CurrentRegion
Set dic = CreateObject("scripting.dictionary")
Set reg = CreateObject("vbscript.regexp")
reg.Pattern = "\d+"
For i = 2 To UBound(arr)
m = Month(arr(i, 2))
strkey = arr(i, 1) & arr(i, 3) & m
If Not dic.exists(strkey) Then
Set dic(strkey) = CreateObject("scripting.dictionary")
End If
For j = 4 To UBound(arr, 2)
If arr(i, j) <> "" Then
dic(strkey)(arr(1, j)) = dic(strkey)(arr(1, j)) + arr(i, j)
End If
Next
Next
brr = [h2].CurrentRegion
For i = 3 To UBound(brr, 2)
If brr(1, i) = "" Then
brr(1, i) = brr(1, i - 1)
End If
Next
For i = 3 To UBound(brr)
For j = 3 To UBound(brr, 2)
If reg.test(brr(1, j)) Then
Set mh = reg.Execute(brr(1, j))
strkey = brr(i, 1) & brr(i, 2) & mh(0)
If dic.exists(strkey) Then
If dic(strkey).exists(brr(2, j)) Then
brr(i, j) = dic(strkey)(brr(2, j))
End If
End If
End If
Next
Next
[h2].CurrentRegion = brr
Set dic = Nothing
Application.ScreenUpdating = True
End Sub
|
评分
-
1
查看全部评分
-
|