Auto update colour of cells referenced from another sheet

Goddess

Board Regular
Joined
Dec 3, 2015
Messages
52
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I tried to use VBA code to reference a cell colour from another sheet. Eg, Sheet1 is the main sheet, where I will change the colour of certain cells as and when required. Sheet2, Sheet3, etc will contain the data, where some cells will reference back to Sheet1 (using formula =Sheet1!$A$10, for example) and the following VBA code to reference the colour as well.

Private Sub Worksheet_Calculate()
'apply cells colors from single-cell formula dependencies/links
Dim Cel As Range
Dim RefCel As Range
On Error Resume Next
For Each Cel In ActiveSheet.UsedRange
If Cel.HasFormula Then
Set RefCel = Evaluate(Mid(Cel.Formula, 2))
Cel.Interior.Color = RefCel.Interior.Color
End If
Next Cel
End Sub

However, when I change the colour in Sheet1, the other sheets does not automatically update the colours. I will need to 'run' the code every time I change the colour. Am I doing anything wrong?

Also, is the any simpler way of doing this, maybe conditional formatting, etc? I'm not very good in VBA. Also, it states that I need to save the file in macro supported Excel file. I'm worried my co-workers can't open the file when I send to them.

Thanks!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,237
Messages
5,768,983
Members
425,507
Latest member
NrthnChrs

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
Top