|
我做练习1'小计之后的数字之和。
Sub Test1()
Dim r&, ar, Reg As Object, br, ss$, mas As Object, ma As Object, v#, Start%, Length%, i&
r = Cells(Rows.Count, 1).End(xlUp).Row
With Range("A1").Resize(r)
.Font.Bold = False
.Font.Color = 0
ar = .Resize(, 2).Value
End With
ReDim br(2 To r, 1 To 1)
Set Reg = CreateObject("VBScript.RegExp")
With Reg
.Global = True
.Pattern = "小计\d+\.?\d*"
For i = 2 To r
ss = ar(i, 1)
Set mas = .Execute(ss)
For Each ma In mas
Start = ma.FirstIndex + 2
Length = ma.Length - 2
v = Val(Right(ma, Len(ma) - 2))
br(i, 1) = br(i, 1) + v
With Range("A" & i).Characters(Start, Length).Font
.Bold = True
.Color = vbBlue
End With
Next
Next
End With
Range("B2").Resize(r - 1) = br
End Sub |
|