CELL FILL COLOR NOT HOLDING ON WORKSHEET

rikvny02

Board Regular
Joined
Aug 9, 2022
Messages
95
Office Version
  1. 365
Platform
  1. Windows
In the below code I am defining the sections of the worksheet id like to highlight. Why will cell fill color of the rest of the worksheet not hold. If I try to fill another cell it just goes back to no fill.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Sheets("raise")
.Cells.Interior.ColorIndex = xlColorIndexNone
Select Case Target.Address
Case "$C$7"
.Range("C16:h16").Interior.Color = RGB(0, 255, 0)
.Range("C7:h7").Interior.Color = RGB(0, 255, 0)
Case "$C$8"
.Range("c17:h17").Interior.Color = RGB(0, 255, 0)
.Range("c8:h8").Interior.Color = RGB(0, 255, 0)
Case "$C$9"
.Range("c18:h18").Interior.Color = RGB(0, 255, 0)
.Range("c9:h9").Interior.Color = RGB(0, 255, 0)
Case "$C$10"
.Range("c19:h19").Interior.Color = RGB(0, 255, 0)
.Range("c10:h10").Interior.Color = RGB(0, 255, 0)
Case "$C$11"
.Range("c20:h20").Interior.Color = RGB(0, 255, 0)
.Range("c11:h11").Interior.Color = RGB(0, 255, 0)
Case "$C$12"
.Range("c21:h21").Interior.Color = RGB(0, 255, 0)
.Range("c12:h12").Interior.Color = RGB(0, 255, 0)
End Select
End With
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Because of your second line of code:
Excel Formula:
.Cells.Interior.ColorIndex = xlColorIndexNone
What this is doing, as you select ANY cell, it removes ALL color from ALL cells, before going in to your CASE statement and formatting the appropriate cells.
So this is acting as a "reset" everytime you move cells.

If you remove that one line of code, all your color changes will be retained.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top