Thread: Highlight Cells
View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
ranswrt ranswrt is offline
external usenet poster
 
Posts: 191
Default Highlight Cells

Thanks I'll work on those.

"ranswrt" wrote:

I tried your code but I have a problem with the 'usedrange'. It is changing
the color on a larger range instead of the previous range. I am not familiar
on how to use that code. How do I change it to just the previous range that
had the color change?


"Rick Rothstein (MVP - VB)" wrote:

Okay, I see what you are trying to highlight now. Try this event code
instead...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
UsedRange.Interior.ColorIndex = xlNone
Cells(Target.Row, 3).Resize(1, 6).Interior.ColorIndex = 36
End Sub

Note that it removes the previous highlight (I tried to guess at your
intent). If you do not want that feature, delete the first line (the
UsedRange one) and leave just the last line.

Rick


"Rick Rothstein (MVP - VB)" wrote in
message ...
I'm not completely sure what range you are trying to color... is it a 3
columns wide by 6 rows deep with the active cell in the upper left of that
rectangle? If so, is this what you want to do...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
UsedRange.Interior.ColorIndex = xlNone
Target.Resize(6, 3).Interior.ColorIndex = 36
End Sub

Rick


"ranswrt" wrote in message
...
I would like to highlight a line of cells when the cell is selected. I
tried
the following code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Dim ycell As Range

Set ycell = ActiveCell.EntireRow.Cells(3)
Set rng = Range(ycell, ycell.Offset(0, 5))
rng.Interior.ColorIndex = 36

End Sub

but I get an error that says 'Unable to set ColorIndex property of the
interior class'.
What am I doing wrong here? or is there a better way to do this?
Thanks