fill a row range with multiple colours

jammoca

Banned
Joined
Nov 6, 2002
Messages
1,100
I'm currently using the following code to fill a row of up to 7 cells with the colour yellow, dependent on where in that row I click.

so, for example, if I click in cell G3, cells C3 to G3 will fill with yellow.

If I were to click in J7, then cells C7 to J7 would fill with yellow.

The code also allows me to change my mind, and click a different cell within a row that I've already clicked a 'shade-range', and choose a different cell to fill up to.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim iColor As Integer
If Intersect(Target, Range("C3:L8")) Is Nothing Then Exit Sub
iColor = Target.Interior.ColorIndex
If iColor < 0 Then iColor = 6
Rows(Target.Row).FormatConditions.Delete
With Range("C" & Target.Row, Target.Address) 'Rows(Target.Row)
    .FormatConditions.Add Type:=2, Formula1:=1
    .FormatConditions(1).Interior.ColorIndex = iColor
End With
End Sub

Is there a way to alter the code so that I get a gradual change of colours (let's say from red through to green) from left to right, up to where I click.

So, for example ...

* if I click in cell C3, C3 would be filled with red
* if I click in cell D3, C3 would be filled with red, and D3 would be filled with a slightly less red
* if I click in cell E3, C3 would be filled with red, D3 would be filled with a slightly less red, E3 would be filled with something a bit more orange

etc etc etc where if I were to click on the right-most cell in the row, let's say L3, I'd have a gradual range of colours from bright red in C3 through to bright green in L3.

The colour range is to reflect bad (alarming red on the left) through to good (affirming green on the right)

Is this possible ?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,215,089
Messages
6,123,058
Members
449,091
Latest member
ikke

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