VBA 已知填充颜色 批量提取RGB数值
我不会VB。已百度。求问,怎么修改能进行批量操作。就是A列已填充颜色,RGB数值结果输出到B列。百度到的这个只是1个单元格。我想要从A2开始到A2000所有的单元格都进行...
我不会VB。已百度。求问,怎么修改能进行批量操作。就是A列已填充颜色,RGB数值结果输出到B列。
百度到的这个只是1个单元格。我想要从A2开始到A2000所有的单元格都进行操作。将结果输出到B2到B2000。直到单元格为“无填充颜色”为止。
Sub Macro1()
'
' Macro1 Macro
'
c = Range("a1").Interior.Color
r = c Mod 256
g = (c - r) / 256 Mod 256
b = (c - r - g * 256) / 256 ^ 2
[B1] = r & " " & g & " " & b
'
End Sub 展开
百度到的这个只是1个单元格。我想要从A2开始到A2000所有的单元格都进行操作。将结果输出到B2到B2000。直到单元格为“无填充颜色”为止。
Sub Macro1()
'
' Macro1 Macro
'
c = Range("a1").Interior.Color
r = c Mod 256
g = (c - r) / 256 Mod 256
b = (c - r - g * 256) / 256 ^ 2
[B1] = r & " " & g & " " & b
'
End Sub 展开
2个回答
展开全部
sub getRGB()
for i=2 to 2000
if Range("A" & i).Interior.ColorIndex=xlNone then exit for
c = Range("A" & i).Interior.Color
r = c Mod 256
g = (c - r) / 256 Mod 256
b = (c - r - g * 256) / 256 ^ 2
cells(i,"B")=r & "," & g & "," & b
next
end sub
引用落叶l无情的回答:
sub getRGB() for i=2 to 2000 if Range("A" & i).Interior.ColorIndex=xlNone then exit for c = Range("A" & i).Interior.Color r = c Mod 256 g = (c - r) / 256 Mod 256 b = (c - r - g * 256) / 256 ^ 2 cells(i,"B")=r & "," & g & "," & b nextend sub
sub getRGB() for i=2 to 2000 if Range("A" & i).Interior.ColorIndex=xlNone then exit for c = Range("A" & i).Interior.Color r = c Mod 256 g = (c - r) / 256 Mod 256 b = (c - r - g * 256) / 256 ^ 2 cells(i,"B")=r & "," & g & "," & b nextend sub
展开全部
Option Explicit
Public Function RGB(a As Range) As String
Application.Volatile
Dim r As Integer, g As Integer, b As Integer
r = a.Interior.COLOR Mod 256
g = (a.Interior.COLOR - r) / 256 Mod 256
b = ((a.Interior.COLOR - g - b * 256) / 256 ^ 2) - 1
RGB = r & "," & g & "," & b
End Function
Public Function RGB(a As Range) As String
Application.Volatile
Dim r As Integer, g As Integer, b As Integer
r = a.Interior.COLOR Mod 256
g = (a.Interior.COLOR - r) / 256 Mod 256
b = ((a.Interior.COLOR - g - b * 256) / 256 ^ 2) - 1
RGB = r & "," & g & "," & b
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |