Excel VBA检查Activecell.Interior.color不工作的单元格颜色

Excel VBA检查Activecell.Interior.color不工作的单元格颜色,vba,excel,colors,Vba,Excel,Colors,我想检查一个单元格是否有某种颜色。如果为true,我需要此消息框(“单元格匹配颜色”)。否则,我希望有消息框(“单元格颜色不匹配”) 当您为变量Refcolor赋值时,只需删除关键字Set Set用于将对象分配给变量,您正在分配原语值 Sub Autoselect() Dim Refcolor As Long Refcolor = RGB(220, 230, 241) If ActiveCell.Interior.Color = Refcolor Then

我想检查一个单元格是否有某种颜色。如果为true,我需要此消息框(“单元格匹配颜色”)。否则,我希望有消息框(“单元格颜色不匹配”)


当您为变量
Refcolor
赋值时,只需删除关键字
Set

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

立即解决了这个问题。非常感谢。
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