- Public Sub tt()
- Dim arr As Variant, i&, n&, reg As Object, j&, matches As Variant, m&, str$
- n = Sheet1.UsedRange.Rows.Count
- arr = Sheet1.Range("a2:a" & n).Value
- Set reg = CreateObject("vbscript.regexp")
- reg.Pattern = "\d"
- reg.Global = True
- For i = 1 To UBound(arr)
- arr(i, 1) = Replace(arr(i, 1), "初一", "7")
- arr(i, 1) = Replace(arr(i, 1), "初二", "8")
- arr(i, 1) = Replace(arr(i, 1), "初三", "9")
- arr(i, 1) = Replace(arr(i, 1), "一十", "1")
- arr(i, 1) = Replace(arr(i, 1), "二十", "2")
- arr(i, 1) = Replace(arr(i, 1), "三十", "3")
- arr(i, 1) = Replace(arr(i, 1), "十班", "10")
- arr(i, 1) = Replace(arr(i, 1), "十", "1")
- arr(i, 1) = Replace(arr(i, 1), "一", "1")
- arr(i, 1) = Replace(arr(i, 1), "二", "2")
- arr(i, 1) = Replace(arr(i, 1), "三", "3")
- arr(i, 1) = Replace(arr(i, 1), "四", "4")
- arr(i, 1) = Replace(arr(i, 1), "五", "5")
- arr(i, 1) = Replace(arr(i, 1), "六", "6")
- arr(i, 1) = Replace(arr(i, 1), "七", "7")
- arr(i, 1) = Replace(arr(i, 1), "八", "8")
- arr(i, 1) = Replace(arr(i, 1), "九", "9")
- Set matches = reg.Execute(arr(i, 1))
- m = matches.Count
- If m > 1 Then
- str = matches(0) & "("
- For j = 1 To m - 1
- str = str & matches(j)
- Next
- str = str & ")班"
- arr(i, 1) = str
- Else
- If arr(i, 1) <> "" Then arr(i, 1) = "匹配错误!请手动核查!"
- End If
- Next
- Sheet1.Range("b2:b" & n).Value = arr
- Set matches = Nothing
- Set reg = Nothing
- End Sub
复制代码
匹配错误的,会让手动核查 |