I am trying to write code that will check only certain cell dependent on row. In this case certain cells that are below a given number are red and rest are green. How ever I am getting an error:
Run-time error '1004': Unable to set the ColorIndex property of the Interior class
Here is the code:
Dim sCell As String
Dim cCell As Integer
sCell = "D"
For cCell = 10 To 47
If cCell = 18 Or cCell = 27 Or cCell = 28 Or cCell = 32 Or cCell = 41 Or cCell = 42 Or cCell = 46 Or cCell = 47 Then
Range(sCell & cCell).Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
Formula1:="=$I" & cCell
Selection.FormatConditions(3).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
, Formula1:="=$I" & cCell
Selection.FormatConditions(3).Interior.ColorIndex = 10
'ElseIf cCell = 17 Or cCell = 30 Or cCell = 31 Or cCell = 34 Or cCell = 35 Or cCell = 40 Or cCell = 43 Or cCell = 45 Then
' Range(sCell & 18).Select
' Selection.FormatConditions.Delete
' Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
' Formula1:="=$I$cCell"
' Selection.FormatConditions(2).Interior.ColorIndex = 3
' Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
' , Formula1:="=$I$cCell"
' Selection.FormatConditions(3).Interior.ColorIndex = 10
End If
Next
End Sub
Tim
Run-time error '1004': Unable to set the ColorIndex property of the Interior class
Here is the code:
Dim sCell As String
Dim cCell As Integer
sCell = "D"
For cCell = 10 To 47
If cCell = 18 Or cCell = 27 Or cCell = 28 Or cCell = 32 Or cCell = 41 Or cCell = 42 Or cCell = 46 Or cCell = 47 Then
Range(sCell & cCell).Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
Formula1:="=$I" & cCell
Selection.FormatConditions(3).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
, Formula1:="=$I" & cCell
Selection.FormatConditions(3).Interior.ColorIndex = 10
'ElseIf cCell = 17 Or cCell = 30 Or cCell = 31 Or cCell = 34 Or cCell = 35 Or cCell = 40 Or cCell = 43 Or cCell = 45 Then
' Range(sCell & 18).Select
' Selection.FormatConditions.Delete
' Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
' Formula1:="=$I$cCell"
' Selection.FormatConditions(2).Interior.ColorIndex = 3
' Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
' , Formula1:="=$I$cCell"
' Selection.FormatConditions(3).Interior.ColorIndex = 10
End If
Next
End Sub
Tim