[英]Conditional formatting using “IF” condition in VBA is not working?
代碼運行沒有任何錯誤,但條件格式不起作用。我們也可以使用地址偏移單元格。 cf = blue.Address(orow / 2 - 1, -ocol / 2)
。
blue.Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
cf = blue.Address(orow / 2 - 1, -ocol / 2)
cf1 = blue.Address(orow / 2 - 1, ocol / 2)
cf2 = blue.Address(-orow / 2 - 1, -ocol / 2)
cf3 = blue.Address(-orow / 2 - 1, ocol / 2)
Selection.FormatConditions.Add Type:=xlExpression, Formula1:=_
"=OR(LEN(cf.address)=0, LEN(cf1.address)=0,LEN(cf2.address)=0,LEN(cf3.address)=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.ThemeColor = xlThemeColorAccent5
.TintAndShade = 0.8
End With
Selection.FormatConditions(1).StopIfTrue = False
End With
並非所有代碼都已發布並且難以評估所有代碼。 但嘗試更換:
"=OR(LEN(cf.address)=0, LEN(cf1.address)=0,LEN(cf2.address)=0,LEN(cf3.address)=0)"
和
"=OR(LEN(" & cf.address & ")=0, LEN(" & cf.address & ")=0,LEN(" & cf.address & ")=0,LEN(" & cf.address & ")=0)"
否則,VBA 將所有內容視為字符串,而不關心您的變量...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.