[英]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.