简体   繁体   English

VBA条件格式下标超出范围

[英]VBA Conditional formatting subscript out of range

Very new to VBA and been working on trying to fix a subscript out of range for hours on the line: .FormatConditions(1).Add Type:=xlCellValue, Operator:=xlLess, _ Formula1:="=0.5" What am I missing? 对VBA来说是非常新的知识,并且一直在尝试解决下标超出范围数小时的问题:.FormatConditions(1).Add Type:= xlCellValue,Operator:= xlLess,_ Formula1:=“ = 0.5”我是什么失踪?

With ActiveSheet
Columns(4).Select
Range("D3").Activate
With Columns("D:D")
    .FormatConditions.Delete
    .FormatConditions(1).Add Type:=xlCellValue, Operator:=xlLess, _
         Formula1:="=0.5"
    .FormatConditions(1).NumberFormat = "0.000"
    .FormatConditions(1).StopIfTrue = False
    .FormatConditions(2).Add Type:=xlCellValue, Operator:=xlGreaterEqual, _
         Formula1:="=0.5"
   .FormatConditions(2).NumberFormat = "#,##0.0"
   .FormatConditions(2).StopIfTrue = False
ActiveSheet.Next.Select

End With
End With
End Sub

Problem with your syntax when adding conditions. 添加条件时语法出现问题。 You can also dispense with the Selects I think. 您也可以省去我认为的精选。

With ActiveSheet.Columns("D:D")
     .FormatConditions.Delete
     .FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
          Formula1:="=0.5"
     .FormatConditions(1).NumberFormat = "0.000"
     .FormatConditions(1).StopIfTrue = False
     .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, _
          Formula1:="=0.5"
    .FormatConditions(2).NumberFormat = "#,##0.0"
    .FormatConditions(2).StopIfTrue = False
End With

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM