|
- Sub test()
- Dim sht As Worksheet
- arr = Sheets("sheet1").[a1].CurrentRegion
- ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
- Set d = CreateObject("scripting.dictionary")
- For i = 2 To UBound(arr)
- If Len(arr(i, 1)) = 5 Then
- If Mid(arr(i, 1), 3, 1) > "6" Then Mid(arr(i, 1), 3, 1) = 6
- Else
- arr(i, 1) = Mid(arr(i, 1), 6, 5)
- End If
- If Not d.exists(arr(i, 1)) Then
- m = m + 1: d(arr(i, 1)) = m: brr(m, 1) = arr(i, 1):
- For j = 2 To UBound(arr, 2)
- brr(m, j) = arr(i, j)
- Next
- Else
- For j = 2 To UBound(arr, 2)
- brr(d(arr(i, 1)), j) = brr(d(arr(i, 1)), j) + arr(i, j)
- Next
- End If
- Next
- [a30].Resize(m, j - 1) = brr
- Application.DisplayAlerts = False
- For Each sht In Sheets
- If sht.Name <> "Sheet1" Then sht.Delete
- Next
- Application.DisplayAlerts = True
- For j = 2 To UBound(arr, 2) - 1
- ReDim crr(1 To m, 1 To 2)
- For i = 1 To m
- crr(i, 1) = brr(i, 1)
- crr(i, 2) = brr(i, j)
- Next
- Sheets.Add(after:=Sheets(Sheets.Count)).Name = arr(1, j)
- With ActiveSheet
- .[a1:b1] = Array("销售终端号", "销售金额")
- .[a2].Resize(m, 2) = crr
- End With
- Next
- 'Stop
- End Sub
复制代码
朋友,你的模拟数据弄了些随机数(偷懒哈),无法检验。。。。。所以疏忽了。
这次好了吗? |
|