Gradient Colour scale for a group of cells based on another cell showing "Y"

Peter Davison

Active Member
Joined
Jun 4, 2020
Messages
444
Office Version
  1. 365
Platform
  1. Windows
Is it possible to use a Gradient Colour scale for a group of cells based on a different cell showing "Y"?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Re: "group of cells".
Each cell it's own color or a range with one color?
If it is a range, can you cover it with a TextBox of that size and fill it with the gradient color?
 
Upvote 0
Found this through Mrs & Mr Google.
Code:
Sub SetGradient()
Dim myrange As Range
Set myrange = ThisWorkbook.Sheets("Sheet2").Range("B2")

    With myrange.Interior
        .Pattern = xlPatternLinearGradient
        .Gradient.Degree = 90
        .Gradient.ColorStops.Clear
    End With
    With myrange.Interior.Gradient.ColorStops.Add(0)
        .Color = 16777215
        .TintAndShade = 0
    End With
    With myrange.Interior.Gradient.ColorStops.Add(0.5)
        .Color = 7961087
        .TintAndShade = 0
    End With
    With myrange.Interior.Gradient.ColorStops.Add(1)
        .Color = 16777215
        .TintAndShade = 0
    End With
End Sub
Not that I know how it works but it might be a start for you.
 
Upvote 0
It is a gradient range from Red to Green based on the cell number contents (Lowers to highest number)
Thank you for the above I'll take a look a little later.
 
Upvote 0
Unfortunately the above code grades each cell the same.
I posted the below in a new enquiry, unfortunately I didn't realise I should have added it to this query. My apologies for that.
Any help with this would be appreciated.
Thanks to all.

--------
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
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,580
Members
449,174
Latest member
chandan4057

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