0
votes

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?

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
1

1 Answers

0
votes

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