Private Sub CommandButton1_Click()
Set Dic = CreateObject("Scripting.Dictionary")
Arr = Sheets("0").Range("A1:K58")--这里是获取单元格的范围和sheet的名称
N = 1
For H = 1 To 58-- 这里是行数
For l = 1 To 11--这里是列数
cV = Cells(H, l).Interior.Color
R = cV \ 256 ^ 0 Mod 256
G = cV \ 256 ^ 1 Mod 256
B = cV \ 256 ^ 2 Mod 256
YS = cV & "," & R & "," & G & "," & B
If Not Dic.exists(YS) Then
Arr(H, l) = N
Dic(YS) = N
N = N + 1
Else
Arr(H, l) = Dic(YS)
End If
Next
Next
Range("A1:K58") = Arr--这里需要处理的区域
Brr = Dic.keys
With Sheets("1")--这里是放RGB值的sheet名称
.Range("A1:K58").Clear--这是放RGB值的区域
For i = 0 To UBound(Brr)
.Cells(i + 2, 1).Interior.Color = Split(Brr(i), ",")(0)
.Cells(i + 2, 2).Resize(, 4) = Array(Split(Brr(i), ",")(1), Split(Brr(i), ",")(2), Split(Brr(i), ",")(3), i + 1)
Next
End With
End Sub
新增一个Active控件
点击查看代码
复制进去就行
范围变化的时候,改一下注释里的相关值就行