[英]Excel VBA check cell color with Activecell.Interior.color not working
I wish to check whether a cell has a certain color. 我想检查一个单元格是否具有某种颜色。 If true, I want this message box ("Cell Match Color").
如果为true,则需要此消息框(“单元格匹配颜色”)。 Otherwise, I wish to have Message box ("Cell does not match color.")
否则,我希望有一个消息框(“单元格与颜色不匹配。”)
Option Explicit
Sub Autoselect()
Dim Refcolor As Long
Set Refcolor = RGB(220, 230, 241)
If ActiveCell.Interior.Color = Refcolor Then MsgBox ("Cell Match
Color") Else: MsgBox ("Cell does not match color")
End Sub
Just remove keyword Set
when you assign value to variable Refcolor
. 将变量赋值给
Refcolor
时,只需删除关键字Set
Refcolor
。
Set
is used to assign objects to variable and you are assigning primitive value. Set
用于将对象分配给变量,并且您正在分配原始值。
Sub Autoselect()
Dim Refcolor As Long
Refcolor = RGB(220, 230, 241)
If ActiveCell.Interior.Color = Refcolor Then
MsgBox ("Cell Match Color")
Else
MsgBox ("Cell does not match color")
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.