Auto update colour of cells referenced from another sheet

Goddess

Board Regular
Joined
Dec 3, 2015
Messages
94
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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,214,987
Messages
6,122,618
Members
449,092
Latest member
amyap

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