custom function recalculation

kendo679

New Member
Joined
Aug 26, 2016
Messages
25
I'm using a custom function but it causes the entire sheet to recalculate no matter what cells I enter data to. Seems like it should only recalc when altering a cell that contains the custom formula.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Maybe your custom function is turning the sheet to auto calculate, hard to know without seeing the function. Excel is supposed to be quite efficient as to what and when it recalculates a sheet
 
Last edited:
Upvote 0
Thanks for your response,

The sheet is set in the options page to auto calculate, but I still don't understand why it does so no matter what cell I alter.
here is the code:
Code:
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)


Application.Volatile
Dim rCell As Range
Dim lCol As Long
Dim vResult
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
If lCol = -4142 Then
vResult = 0
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function
 
Upvote 0
I even commented out the "Application.Volatile" and it still recalculates every time I change anything on the sheet
I inserted a msgbox to prove that the function is running. There are dozens of cells with the custom formula so I had to hold the enter key down for 5 seconds while it ran through them all.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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