看板 Visual_Basic 關於我們 聯絡資訊
版本:Microsoft Office 2007 本人為剛接觸VBA新手 目前使用錄製巨集 錄製<格式化條件> 程式如下 Range("B4").Select Range(Selection, Selection.End(xlDown)).Select Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _ Formula1:="=100", Formula2:="=50" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 5296274 .TintAndShade = 0 End With Selection.FormatConditions(1).StopIfTrue = False 上面表示選取範圍儲存格內數字介於50~100,底色變為淺綠色 這邊有個疑問想請教! 如何下判斷,當範圍內皆為淺綠色跳出MSGBOX顯示"OK" 以下為自己寫的判斷式(下列皆無法有效判斷) If Range("B4").Interior.Color = RGB(146, 208, 80) Then MsgBox "OK" End If -------無法判斷 If Range("B4").Interior.Color = 5296274 Then MsgBox "OK" End If -------任何顏色都會顯示OK 這邊先是測試單一儲存格能否做判斷,最終是要判斷範圍內所有儲存格 PS:淺綠色RGB(146,208,80) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.241.172.206 ※ 文章網址: https://www.ptt.cc/bbs/Visual_Basic/M.1559312106.A.84E.html
noworneverev: 你寫的兩段是可以判斷 沒問題阿 06/01 07:56
sf4566373: https://imgur.com/WNfgnpo 06/01 09:49
sf4566373: https://imgur.com/TKYhPZy 06/01 09:50
sf4566373: 我用逐行執行判斷B4儲存格,B4為粉紅色底色仍判斷成功 06/01 09:51
sf4566373: 事實上任何顏色都會判斷OK = = 還是版本有差啊>< 06/01 09:52
olycats: 請問B4是原本就粉紅色,還是格式化條件後變成粉紅色的? 06/02 22:41
olycats: 最後一段 是針對儲存格本身的底色去判斷 06/02 22:48
olycats: 如果是格式化條件之後改變的顏色則無法判斷 06/02 22:48
sf4566373: 原來是格式化關係 = = 06/04 21:27