Change Cell background color by selection

B

Bob Wall

Excel 2003

I have a table of data, and I would like to have a section of it highlighted
with a different background color when the user selects the first cell in
the row (selecting this cell also drives a couple of other functions as well
using the Worksheet_SelectionChange function).

The table range is from A7:D14.
When A7 is selected, I'd like to have A7:D7 background change to yellow.
When a different cell is selected, I need A7:D14 to revert back to their
original
format (gray background) and have the new selection change to the yellow
background.

Any thoughts will be greatly appreciated!
 
G

Guest

Put this in worksheet code:


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim block As Range
Dim point As Range
Set block = Range(Cells(7, 1), Cells(14, 4))
Set point = Cells(7, 1)

Cells.Interior.ColorIndex = xlNone

If Not Intersect(Target, point) Is Nothing Then
block.Interior.ColorIndex = 6
Else
Target.Interior.ColorIndex = 6
End If
End Sub


If A7 is selected, the block will be yellow. If any other cell is selected,
then that cell is made yellow.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top