Update calculation of user defined formulae

NoviceCoder

New Member
Joined
Apr 26, 2016
Messages
20
Hi
I've encountered a frustrating and seemingly simple problem. I have a user defined formula that counts colloured cells in excel. But the calculation does not update when cells are changed like they would would standard excel function like "Sum" or "Countif". The "application. volatile" doesn't fix this and the only way i can update is to selection the cell and re-enter the fourmula. Ive seen some comments online but none seem to resolve this fairly basic problem. Any help very much appreciated. Thank you

Function COUNTIFCOLOUR(Colour As Range, rng As Range) As Long

Application.Volatile

Dim NoCells As Long
Dim CellColour As Long
Dim rngCell As Range
CellColour = Colour.Interior.Color
For Each rngCell In rng
If rngCell.Interior.Color = CellColour Then
NoCells = NoCells + 1
End If
Next
COUNTIFCOLOUR = NoCells
End Function
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
The only way would be to have a worksheet selectionchange event that forces the sheet to recalculate.
 
Upvote 0
What kind of changes are we talking about, exactly?
How are the cells being updated?
Its an activity tracker and each cell represents a block of time. depending on the activity the cell colour is modified. The cells contains UDF (countifcolour) summarise the number of cells for each activity.
 
Upvote 0
The only way would be to have a worksheet selectionchange event that forces the sheet to recalculate.
The sheet is an activity tracker with a row for each day of the week and a column for each 10min block. each cell is colour coded by the activity. The grid is replicated week after week. Besides each week is a series of cells summarising activity according to activity .e.g. activity A (colour red) may be 10 cells or 5%. So I would only want selection change in part of the worksheet to trigger the related summary cells for each activity. I hope that's makes sense.
 
Upvote 0
Are the cell colours being changed manually?
 
Upvote 0
The problem is that changing a cells color doesn't trigger calculation or a worksheet Change event (or any event).
Even Fluff's SelectionChange workaround wouldn't be current until the user selected a different cell.
 
Upvote 0
It would be much better to put a value into the cells representing the activity type, then have the colours change based on the value. Then your formulas are simple COUNTIF formulas.
 
Upvote 0
It would be much better to put a value into the cells representing the activity type, then have the colours change based on the value. Then your formulas are simple COUNTIF formulas.
Yes i agree but the coloured box concept is very visual and its a routine that multiple users are familiar with and are reliable at performing. I did consider getting cells to be filled with a number with font colour of the background and then the Countif function could be used. To achieve this i created code with a shape that appeared when a time cell was selected and the shape included a panel of coloured box/shapes (This was a kind of user defined pop-up coloured Form). When appropriate coloured box/shape was clicked the time cell colour would change (and the number would be [secretly] inserted too. It was quite elaborate and worked but was prone to bugging.
 
Upvote 0
Then you're pretty much stuck with the limitations of your current function.
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,013
Members
448,935
Latest member
ijat

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