- Sub mytest()
- Dim rex As Object, mat, j
- Dim ar, br(1 To 4, 1 To 10), a%, y%
- ar = Range("a1:i4")
- Set rex = CreateObject("vbscript.regexp")
- With rex
- .Global = True
- .Pattern = "\d+\w+|\d+"
- For a = 2 To UBound(ar)
- For y = 1 To 6
- br(a, y) = ar(a, y)
- br(1, y) = ar(1, y)
- Next y
- br(a, 10) = ar(a, 9)
- br(a, 9) = ar(a, 8)
- Set mat = .Execute(ar(a, 7))
- If mat.Count <> 0 Then
- For Each j In mat '
- br(a, 8) = j
- br(a, 7) = Replace(ar(a, 7), j, "")
- Next j
- Else
- br(a, 8) = ""
- br(a, 7) = ar(a, 7)
- End If
- Next a
- br(1, 7) = "抬头": br(1, 8) = "税号": br(1, 9) = "联系电话": br(1, 10) = "发票签收"
- End With
- With Range("a8").Resize(4, 10)
- .Clear
- .NumberFormatLocal = "@"
- .Value = br
- .Borders.LineStyle = True
- End With
- End Sub
复制代码 |