- Sub aa()
- Dim ar, i, ar1(1 To 10000, 1 To 6), k, d, m, n, s, s1, j, p
- Set d = CreateObject("vbscript.regexp")
- ar = Sheet1.UsedRange
- With d
- .Global = True
- .Pattern = "[A-Z]+.*?(\s|[A-Z]\s)|\d+(?=\.)"
- End With
- For i = 2 To UBound(ar)
- If InStr(ar(i, 5), Chr(10)) Then
- s = Len(ar(i, 5)) - Len(Replace(ar(i, 5), Chr(10), ""))
- For k = 0 To s
- s1 = Split(ar(i, 5), Chr(10))(k)
- If s1 <> "" Then
- j = j + 1
- ar1(j, 1) = ar(i, 1)
- ar1(j, 2) = ar(i, 4)
- Set m = d.Execute(s1)
- For n = 0 To m.Count - 1
- ar1(j, n + 3) = m(n)
- Next
- End If
- Next
- p = j
- Else
- p = p + 1
- s1 = ar(i, 5)
- ar1(p, 1) = ar(i, 1)
- ar1(p, 2) = ar(i, 4)
- Set m = d.Execute(s1)
- For n = 0 To m.Count - 1
- ar1(p, n + 3) = m(n)
- Next
- End If
- Next
- Sheet2.[a1].Resize(UBound(ar1), UBound(ar1, 2)) = Array("销售订单", "客户名称", "产品型号", "数量", "单价(含税)", "销售额(含税)")
- Sheet2.[a2].Resize(UBound(ar1), UBound(ar1, 2)) = ar1
- Set d = Nothing
- End Sub
复制代码 |