Changing cell color with SelectionChange
Posted by Rich on January 18, 2002 4:50 AM
This seems to be a simple problem, but I'm constantly getting an error message.
I have a table across the range A1:J10. The first row (B1:J1) is the header row, and the first column (A2:A10) is the header column (A1 is the dead space). Both headers are gray (color 48). What I would like to do is highlight the individual cells in the header row and column that correspond to a cell selection within the table (range B2:J10). In other words, if F5 is selected, cells F1 and A5 would become red.
The code is copied below, but I keep getting the following error message:
Run-time error '1004': Unable to set the ColorIndex property of the Interior class.
Does anybody have any thoughts on this???
----------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim R, C
R = Target.Row
C = Target.Column
Application.ScreenUpdating = False
ActiveSheet.Unprotect
Range("A1:A10").Select
With Selection.Interior
.ColorIndex = 48 ' <--- PROBLEM
.Pattern = xlSolid
End With
Range("A1:J10").Select
With Selection.Interior
.ColorIndex = 48
.Pattern = xlSolid
End With
ActiveSheet.Cells(R, 1).Select
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
ActiveSheet.Cells(1, C).Select
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
ActiveSheet.Protect DrawingObjects:=True,
_Contents:=True, Scenarios:=True
End Sub