Conditional Format gradient low number to high number

Status
Not open for further replies.

Peter Davison

Active Member
Joined
Jun 4, 2020
Messages
451
Office Version
  1. 365
Platform
  1. Windows
I have a range of rows/columns starting at I10 to AA10 and the number of rows can be different.
I have been looking for some code that can add this gradient conditional format but only if Cell D7 = "Y"

Each row needs its own gradient rather than all rows in the same gradient.

I found the code below from Fluff but I cant work out how to make it work for what I need?

If you can help it would be appreciated.

This is the code I found and have just changed the sheet name/cells

Sub GradientColour()
Dim Cl As Range, Rng As Range
Dim Mn As Long, Mx As Long, Av As Long
Dim LowClr As Variant, MidClr As Variant, HighClr As Variant

LowClr = Array(99, 190, 123)
MidClr = Array(255, 235, 132)
HighClr = Array(248, 107, 107)

Set Rng = Range("I10:AA10", Range("I" & Rows.Count).End(xlUp))

Mn = Application.Min(Rng)
Mx = Application.Max(Rng)
Av = Application.Percentile(Rng, 0.5)

Sheets("Report Writer").Select
Range("I10").Select

For Each Cl In Rng
If Cl <= Av Then
Cl.Offset(, 1).Interior.Color = GetColour(LowClr, MidClr, (Cl - Mn), (Av - Mn))
Else
Cl.Offset(, 1).Interior.Color = GetColour(HighClr, MidClr, (Cl - Mx), (Av - Mx))
End If
Next Cl
End Sub
Function GetColour(BaseClr As Variant, MidClr As Variant, Dif As Long, Avg As Long) As Long
Dim i As Long
Dim Clr As Double

For i = 0 To 2
Clr = (MidClr(i) - BaseClr(i)) / Avg
GetColour = GetColour + Int((Dif * Clr + BaseClr(i))) * 256 ^ i
Next i
End Function
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Status
Not open for further replies.

Forum statistics

Threads
1,223,237
Messages
6,170,930
Members
452,367
Latest member
TePunaBloke

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