[英]Can I remove a reference to a specific cell in a rule containing a formula so I can reuse it across multiple columns?
我正在嘗試將相同的規則應用於不同的列,如果它是空的,它將用綠色填充單元格。
我通過錄制宏獲得了規則,但無法找到一種成功的方法來刪除對下面范圍 B2 的引用。
我想把它作為一項規則,我可以將其應用於多個選定的列。
有什么我可以代替的嗎?
Public Sub FillGreenIfCellNotEmpty()
selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=LEN(TRIM(B2))>0"
selection.FormatConditions(selection.FormatConditions.count).SetFirstPriority
With selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0
End With
selection.FormatConditions(1).StopIfTrue = False
End sub
我試過用“cells(1,1)”代替 B2 來引用選區的第一個單元格,並用“selection”代替。
目前,我不完全了解規則如何與即時更新一起使用。 我原以為公式會更符合 if not isempty(selection) 而不是 LEN() 和 TRIM()
請試試這個:
Option Explicit
Public Sub FillGreenIfCellNotEmpty()
Dim x As String
x = Selection.Address(0, 0)
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=LEN(TRIM(" & x & " ))>0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub
突出顯示非空白單元格
Selection.FormatConditions.Add _
Type:=xlCellValue, _
Operator:=xlNotEqual, _
Formula1:="="""""
突出顯示空白單元格
Selection.FormatConditions.Add _
Type:=xlCellValue, _
Operator:=xlEqual, _
Formula1:="="""""
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.