How to get UDF to calculate on WB open?

jbaich

Board Regular
Joined
Nov 2, 2011
Messages
139
Hey all, I have this UDF to emulate the Subtotal function for calculating the median on visible cells only within a range, but it seems to rarely (if ever) calculate when I open the workbook... I have to enter or tab through each cell containing the function in order to get a value rather than the #NUM error. Is there anything I can do to fix this? here is the function:

Code:
Option Explicit

Function MEDIANSUBTOTAL(r As Range)
    Dim v As Variant
    v = Evaluate("MEDIAN(IF(SUBTOTAL(2,OFFSET(" & r.Address & ",ROW(" & r.Address & ")-MIN(ROW(" & r.Address & ")),0,1))," & r.Address & "))")
    If IsError(v) Then
        MEDIANSUBTOTAL = CVErr(xlErrNum)
    Else
        MEDIANSUBTOTAL = v
    End If
End Function

I was hoping i could use the IFError function with it to prompt it to calculate, but that doesn't seem work...

Thanks,
joe
 

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.

Forum statistics

Threads
1,215,473
Messages
6,125,020
Members
449,203
Latest member
tungnmqn90

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