Board logo

標題: [發問] 改變特定儲存格顏色 [打印本頁]

作者: caichen3    時間: 2012-4-10 13:03     標題: 改變特定儲存格顏色

請教各位大大~
M1:M3  有3個數值,想從G欄尋找這三個數值,找到後希望將這三個數值的所在儲存格顏色改為紅色,以下是我的程式碼,能幫我看看!

Dim bbb as string
Dim findstr As String
Dim findrng As Range
mmm = Chr(77)
FOR L=1 TO 3
        bbb=L
        findstr=range(mmm+bbb).value
        Set findrng = Cells.Find(what:=findstr, LookIn:=xlValues, LookAt:=xlWhole)
         findrng.Interior.Color = RGB(255, 0, 0)
Next L
作者: GBKEE    時間: 2012-4-10 14:07

回復 1# caichen3
工作表:  設定格式化條件 步驟
選擇範圍 [G3:G13]
指令: 格式->設定格式化條件
條件一 選擇 公式:=OR(G3=$M$1,G3=$M$2,G3=$M$3)
按下 格式:  可選擇 字型, 外框, 圖樣  設定之
  1. Option Explicit
  2. Sub Ex()   'Vba 設定格式化條件
  3.      With Sheet2.Range("G3:G13")
  4.         .FormatConditions.Delete
  5.         .FormatConditions.Add Type:=xlExpression, Formula1:= _
  6.         "=OR(G3=$M$1,G3=$M$2,G3=$M$3)"
  7.         .FormatConditions(1).Interior.Color = RGB(255, 0, 0)
  8.     End With
  9. End Sub
  10. Sub Ex1()  '修改你的程式碼
  11.     Dim E As Range
  12.     With Sheet2
  13.         For Each E In .Range("G3:G13")
  14.             If E = .[M1] Or E = .[M2] Or E = .[M3] Then
  15.                 E.Interior.Color = RGB(255, 0, 0)
  16.             Else
  17.                 E.Interior.ColorIndex = xlNone
  18.             End If
  19.         Next
  20.     End With
  21. End Sub
複製代碼

作者: caichen3    時間: 2012-4-10 15:24

請問預先 設定格式化條件  的目的是為什麼呢?




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)