vba code updating with changes to cell color

xjpx

New Member
Joined
Jan 3, 2022
Messages
25
Office Version
  1. 365
Platform
  1. Windows
Hi all, I have a code below that counts the number of coloured cells of a specific colour. The problem is that it does not recalculate when the cell colour changes. It only updates when I type something in the sheet. From what I understand this is due to
VBA Code:
Application.Volatile
This does not trigger recalculation due to cell colour changes. Is there a way to make my code trigger a recalculation when there are cell colour changes?
VBA Code:
Function ColorFunction(rColor As Range, rRange As Range)
Dim rCell As Range
Dim lCol As Long
Dim vResult

Application.Volatile

lCol = rColor.Interior.ColorIndex
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell

ColorFunction = vResult
End Function
Thanks!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Is there a way to make my code trigger a recalculation when there are cell colour changes?
No, there is no way to detect that the colour of a cell has been changed. The best you can do is to use a selection change event to recalculate the sheet, but that could cause your workbook to slow down.
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

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