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
 
Are the cell colours being changed manually?
yes the cell colours are being changed manually. Looking at the thread so far it looks as though selection change maybe the best solution. Is there a way in which selection change in rows 1-7 (week 1) changes updates the formula in those rows only. And the same in rows 8-14 (week 2), etc. I don't want to recalculate all formula in the entire worksheet if the summary data only relates to a particular week.
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
It will recalculate every formula on that sheet.
 
Upvote 0
How how about
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   If Not Intersect(Target, Range("D14:DQ18")) Is Nothing Then
      Me.Calculate
   End If
End Sub
 
Upvote 0
Solution
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,955
Latest member
BatCoder

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