Hi All,
I am trying to use the following macro to format cells depending on cell value. When I run it I get the error message "Method'Range' of object' Global'Failed.
Can anyone help.
Thanks,
Rennie
Sub ColourCells()
Dim rMyCell As Range
For Each rMyCell In Range("DataRange")
If rMyCell.Value = "1" Then
Selection.Interior.ColorIndex = 6
ElseIf rMyCell.Value = "2" Then
Selection.Interior.ColorIndex = 7
ElseIf rMyCell.Value = "3" Then
Selection.Interior.ColorIndex = 8
ElseIf rMyCell.Value = "4" Then
Selection.Interior.ColorIndex = 9
ElseIf rMyCell.Value = "5" Then
Selection.Interior.ColorIndex = 10
ElseIf rMyCell.Value = "6" Then
Selection.Interior.ColorIndex = 11
Else
Selection.Interior.ColorIndex = xlNone
End If
Next rMyCell
End Sub