Mirror Conditional formatting

Lazaruss

New Member
Joined
Jun 22, 2016
Messages
4
Hello

I have 2 sheets, Sheet1 has a list of recipie ingredients in each column Sheet2 has the below formula in each cell to calculate how many times a specific ingredient is used

=COUNTIF(Sheet1!$A$1:Sheet1!$Z$16000,Sheet1!A1)

I have setup a graded color scale conditional formatting on sheet2 so that the colour of the cell is darker as the number gets higher. So the more an ingredient is used the darker the cell.

What I would like to do is to mirror the cell colors applied by the graded color scale conditional formatting on sheet2 to the cells with the ingredient names in Sheet2.

Now I understand this is difficult because the CF background colour does not us Interior.Color so a work around would be to create VBA code which mimics CF but uses Interior.Color to set the background colour. After alot of googling I found code which does this and modified it so it mimics the CF I had setup on Sheet2:

Code:
Sub ColouringIn()

    Dim intColIndex As Integer
    Dim dblMax As Double
    Dim dblMin As Double
    Dim rngCell As Range

    dblMax = Application.WorksheetFunction.Max(Sheet2.Range("A1:ZZ100"))
    dblMin = Application.WorksheetFunction.Min(Sheet2.Range("A1:ZZ100"))

    For Each rngCell In Sheet2.Range("A1:ZZ100")
        If IsNumeric(rngCell.Value) And rngCell.Value <> "" Then
            intColIndex = (rngCell.Value - dblMax) / (dblMin - dblMax) * 255
            rngCell.Interior.Color(Sheet1.Range("A1:ZZ100")) = RGB(255, intColIndex, intColIndex)
        End If
    Next rngCell
   

End Sub

I have little coding experience so all I was able to do was apply the background colour to the cells in sheet2 but couldnt work out how to get the corresponding cells in Sheet1 to do the same. I understand its probably a small change to the above code but it is beond my coding capabilitys.

Thanks!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,214,983
Messages
6,122,588
Members
449,089
Latest member
Motoracer88

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