|
参与一下。。。
- Sub ykcbf() '//2024.8.29
- Set d = CreateObject("Scripting.Dictionary")
- With Sheets("数据源")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .[a1].Resize(r, 7)
- End With
- ReDim brr(1 To r, 1 To 4)
- ReDim crr(1 To r, 1 To 4)
- For j = 2 To UBound(arr, 2) Step 3
- For i = 2 To UBound(arr)
- If arr(i, j) <> 0 Then
- If Left(CStr(arr(i, 1)), 1) = "3" Then
- s = arr(i, j) & "3开头"
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = arr(i, j)
- brr(m, 2) = arr(i, j + 1)
- brr(m, 3) = arr(i, j + 2)
- brr(m, 4) = "3开头"
- Else
- r = d(s)
- brr(m, 2) = brr(m, 2) + arr(i, j + 1)
- brr(m, 3) = brr(m, 3) + arr(i, j + 2)
- End If
- Else
- s = arr(i, j) & "其它"
- If Not d.exists(s) Then
- n = n + 1
- d(s) = n
- crr(n, 1) = arr(i, j)
- crr(n, 2) = arr(i, j + 1)
- crr(n, 3) = arr(i, j + 2)
- crr(n, 4) = "其它"
- Else
- r = d(s)
- crr(n, 2) = crr(n, 2) + arr(i, j + 1)
- crr(n, 3) = crr(n, 3) + arr(i, j + 2)
- End If
- End If
- End If
- Next
- Next
- With Sheets("Sheet1")
- .[l2:o1000] = ""
- .[l2].Resize(m, 4) = brr
- r = .Cells(Rows.Count, "l").End(3).Row
- .Cells(r + 1, 12).Resize(n, 4) = crr
- Set Rng = .[l2].Resize(m + n, 4)
- Rng.Sort Rng.Columns(1), 1
- End With
- End Sub
复制代码
|
|