|
本帖最后由 YZC51 于 2018-8-19 18:12 编辑
学习 chxw68 老师的代码。谢谢老师!
Sub test()
Dim r%, i%
Dim arr, brr
Dim reg As New RegExp
With reg
.Global = True
.Pattern = "^RB_(\d+);RW_(\d+)*"
Set mh = .Execute(Range("b2"))
End With
With Worksheets("test")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a2:d" & r)
ReDim brr(1 To UBound(arr), 1 To 4)
For i = 1 To UBound(arr)
brr(i, 1) = arr(i, 1)
Set mh = reg.Execute(arr(i, 2))
Set mh1 = reg.Execute(arr(i, 3))
If mh.Count > 0 Then
brr(i, 3) = brr(i, 3) + Val(mh(0).SubMatches(0))
brr(i, 4) = brr(i, 4) + Val(mh(0).SubMatches(1))
brr(i, 3) = brr(i, 3) + Val(mh1(0).SubMatches(0))
brr(i, 4) = brr(i, 4) + Val(mh1(0).SubMatches(1))
End If
brr(i, 2) = brr(i, 3) + brr(i, 4)
Next
.Range("i2").Resize(UBound(brr), UBound(brr, 2)) = brr
Range("I2:I" & UBound(brr)).NumberFormatLocal = "yyyy/mm/dd hh"
End With
End Sub
|
|