|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
练习一下。
- Sub ykcbf() '//2024.6.16
- Dim arr, brr, d, s
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- ReDim brr(1 To 100000, 1 To 100)
- m = 1: n = 3
- With Sheets("Sheet1")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .[a1].Resize(r, 6)
- brr(1, 1) = arr(1, 2)
- brr(1, 2) = arr(1, 3)
- brr(1, 3) = arr(1, 4)
- For i = 2 To UBound(arr)
- If arr(i, 4) <> 4 Then
- If arr(i, 1) <> Empty Then
- s = arr(i, 2) & "|" & arr(i, 3) & "|" & arr(i, 4)
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = arr(i, 2)
- brr(m, 2) = arr(i, 3)
- brr(m, 3) = arr(i, 4)
- End If
- r = d(arr(i, 2) & "|" & arr(i, 3) & "|" & arr(i, 4))
- s = arr(i, 5)
- If Not d.exists(s) Then
- n = n + 1
- d(s) = n
- brr(1, n) = "产品等级" & s
- End If
- c = d(arr(i, 5))
- brr(r, c) = brr(r, c) + arr(i, 6)
- End If
- End If
- Next
- End With
- With Sheets("结果")
- .UsedRange.Clear
- .[a1].Resize(m, n) = brr
- .[a1].Resize(1, n).Interior.Color = 49407
- ActiveWindow.DisplayZeros = False
- Set Rng = .[a1].Resize(m, n)
- With Rng
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .EntireColumn.AutoFit
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- End With
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
评分
-
2
查看全部评分
-
|