|
先选定被统计区域,再执行宏
Public Sub rt()
Dim co(), x As Range, n, num(), i
For i = 1 To Selection.Count
If i = 1 Then n = n + 1: ReDim Preserve co(1 To n): co(n) = Selection(i).Interior.ColorIndex: GoTo 100
If IsNumeric(Application.Match(Selection(i).Interior.ColorIndex, co, 0)) = False Then
n = n + 1
ReDim Preserve co(1 To n): co(n) = Selection(i).Interior.ColorIndex
End If
100:
Next
ReDim num(1 To n)
For i = 1 To Selection.Count
num(Application.Match(Selection(i).Interior.ColorIndex, co, 0)) = num(Application.Match(Selection(i).Interior.ColorIndex, co, 0)) + 1
Next i
For i = 1 To UBound(co)
[f3].Offset(i).Interior.ColorIndex = co(i)
Next i
[f3:h3] = Array("颜色", "颜色代码", "数量")
[g4].Resize(UBound(co), 1) = Application.Transpose(co)
[h4].Resize(UBound(num), 1) = Application.Transpose(num)
End Sub
|
|