[英]VBA invalid procedure call or argument: Conditional formatting for items stored in an array
[英]How to Write VBA Conditional Formatting Between Cell Values (Invalid procedure, Call or argument)
当单元格介于某些值之间时,我正在尝试将条件格式应用于单元格。
我收到运行时错误“5”:无效的过程调用或参数。
我需要使用 VBA 来执行此操作,因为当我插入行时单元格引用(我想要应用的)会变得混乱。
我查看了多段以不同方式解决问题的示例代码,但是当我尝试复制时没有成功。 我对 VBA 很陌生(并且是自学的),所以这可能是一个非常简单、明显的问题。
With Sheets("Reconciliation").Range("K9:K66")
.FormatConditions.Delete
.FormatConditions.Add Type:=x1CellValue, Operator:=x1Between, Formula1:="=-10", Formula2:="=-0.1"
.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
.FormatConditions.Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
解决方案
当我使用宏记录器时,我得到:
Range("K9:K66").Select
ActiveWindow.SmallScroll Down:=-24
Range("K9:K66,O9:O66").Select
Range("O9").Activate
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="=-10", Formula2:="=-0.1"
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
我将其修改为:
Range("K9:K66,O9:O66").FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="=-10", Formula2:="=-0.1"
Range("K9:K66,O9:O66").FormatConditions(Range("K9:K66,O9:O66").FormatConditions.Count).SetFirstPriority
With Range("K9:K66,O9:O66").FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Range("K9:K66,O9:O66").FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Range("K9:K66,O9:O66").FormatConditions(1).StopIfTrue = False
现在可以了
当我使用宏记录器时,我得到:
Range("K9:K66").Select
ActiveWindow.SmallScroll Down:=-24
Range("K9:K66,O9:O66").Select
Range("O9").Activate
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="=-10", Formula2:="=-0.1"
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
我将其修改为:
Range("K9:K66,O9:O66").FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="=-10", Formula2:="=-0.1"
Range("K9:K66,O9:O66").FormatConditions(Range("K9:K66,O9:O66").FormatConditions.Count).SetFirstPriority
With Range("K9:K66,O9:O66").FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Range("K9:K66,O9:O66").FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Range("K9:K66,O9:O66").FormatConditions(1).StopIfTrue = False
现在可以了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.