ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Change Cell background color by selection (https://www.excelbanter.com/excel-worksheet-functions/107249-change-cell-background-color-selection.html)

Bob Wall

Change Cell background color by selection
 
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!






Gary''s Student

Change Cell background color by selection
 
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.
--
Gary's Student


"Bob Wall" wrote:

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!








All times are GMT +1. The time now is 03:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com