|
- Sub test()
- Dim reGxp As Object, Arr, i&, j&, tmPobj As Object, m As Object, x, a, b
- Set reGxp = CreateObject("vbScript.regExp")
- reGxp.Global = True
- reGxp.Pattern = "(\d+)(\-\D+(\d+))?"
- i = Cells(Rows.Count, "A").End(3).Row
- Arr = [a1].Resize(i, 4)
- With reGxp
- For i = 2 To UBound(Arr, 1)
- If .test(Arr(i, 2)) Then
- x = 0
- Set tmPobj = .Execute(Arr(i, 2))
- For Each m In tmPobj
- If m.submatches(2) & "" <> "" Then
- x = x + 1 + Val(m.submatches(2)) - Val(m.submatches(0))
- Else
- x = x + 1
- End If
- Next m
- Arr(i, 3) = x
- End If
- Arr(i, 4) = IIf(Arr(i, 1) = Arr(i, 3), "对", "X")
- Next i
- End With
- [a1].Resize(UBound(Arr, 1), UBound(Arr, 2)) = Arr
- End Sub
复制代码
|
|