返回列表 上一主題 發帖

[發問] 使用VBA程式自動設定格式化條件變成無法變色

[發問] 使用VBA程式自動設定格式化條件變成無法變色

使用VBA程式自動設定格式化條件變成無法變色.

     來源範圍 = "$" & "D" & "$" & 數字          '帶入此變數設定格式化條件變成無法變色
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
        Formula1:=(來源範圍)                                                            '帶入此變數設定格式化條件變成無法變色
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Color = -16383844
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 13551615
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False

請問各位先進是那裡出錯? 請您教導,謝謝! 原物料量內控表.rar (243.24 KB)

回復 1# kuan-007

有空幫我試試看是不是你要的  感謝

原物料量內控表.rar (37.22 KB)

TOP

雖然不是正解,但多學一招,謝謝你!

TOP

本帖最後由 軒云熊 於 2021-2-23 20:29 編輯

回復 3# kuan-007

抱歉 kuan-007大大  如果有多餘的時間 可以告訴我問題出在哪裡嗎?  我想知道你要的結果 因為我也是順便練習 希望我們可以互相幫助 謝謝你

TOP

回復 1# kuan-007


來源範圍 = "$" & "D" & "$" & 數字
這是文字變數

若要設成範圍變數
set 來源範圍 = Range("$" & "D" & "$" & 數字)
{...} 表示需要用 CTRL+SHIFT+ENTER 三鍵輸入公式

TOP

來源範圍 = "$D$" & 數字
    With Cells(數字, 英文).FormatConditions
         .Delete
         .Add Type:=xlCellValue, Operator:=xlGreater, Formula1:="=" & 來源範圍  '大于
         .Parent.FormatConditions(1).Font.ColorIndex = 3
         .Parent.FormatConditions(1).Interior.ColorIndex = 6
         .Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=" & 來源範圍  '等于
         .Parent.FormatConditions(2).Font.ColorIndex = 5
         .Parent.FormatConditions(2).Interior.ColorIndex = 8
         .Add Type:=xlCellValue, Operator:=xlLess, Formula1:="=" & 來源範圍   '小于
         .Parent.FormatConditions(3).Font.ColorIndex = 7
         .Parent.FormatConditions(3).Interior.ColorIndex = 10
    End With

TOP

        靜思自在 : 【是否發揮了良能?】人間壽命因為短暫,才更顯得珍貴。難得來一趟人間,應問是否為人間發揮了自己的良能,而不要一味求長壽。
返回列表 上一主題