[英]Excel VBA check cell color with Activecell.Interior.color not working
我想检查一个单元格是否具有某种颜色。 如果为true,则需要此消息框(“单元格匹配颜色”)。 否则,我希望有一个消息框(“单元格与颜色不匹配。”)
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
将变量赋值给Refcolor
时,只需删除关键字Set
Refcolor
。
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.