Cell Colour

Simont485

Board Regular
Joined
May 19, 2018
Messages
50
I have found VBA code from another thread that returns a value for a cell colour. But it will only update when F9 is pressed for a cell colour change

In B1 =GetColor(A1) when colour in A1 changes B1 output stays the same

CODE:

Function GetColor(r As Range) As Integer
Application.Volatile
GetColor = r.Interior.ColorIndex
End Function


Is it possible to have this update automatically?
 

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.
There is no defined Event that is triggered when the format of a cell changes

But there may still be a way "create" one based on something else that happens at the same time

How is the colour changed? Do you simply select the cell and manually change it?
 
Upvote 0
It is not possible to detect the change of colour unless user "does" something else afterwards

How about one of these?

Option 1
- amend cell colour and double-click in cell A1 to update the formula

Place this in the SHEET module (not a standard module)
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Address = "$A$1" Then
        Cancel = True
        [A1].Calculate
    End If
End Sub

Option 2

- amend cell colour and click on any other cell to update the formula

Place this in the SHEET module (not a standard module)
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address <> "$A$1" Then [A1].Calculate
End Sub
 
Last edited:
Upvote 0
You could narrow down the range of cells to only those immediately surrounding A1 to prevent the calculation taking place whenever any cell in the worksheet is selected.
Let us know if you need help doing that.
 
Upvote 0

Forum statistics

Threads
1,224,929
Messages
6,181,812
Members
453,067
Latest member
mdiz777

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