VBA Worksheet Funtion Won't Recalculate

soteman2005

New Member
Joined
Nov 24, 2005
Messages
32
Hi,

I have created a function in VBA to use in my excel worksheets. It is an "if" function referring to a number on a different sheet i.e. =if(sheet2!H15=1,do this,do that). It works fine except that it won't recalculate when I change the number on the other sheet. I have to press shift + F9 in order for it to give me the correct value. I have tried application.volatile but it doesn;t have any effect. Any suggestions?

Thanks

Adam
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Show the VBA please. And tell how exactly you tried Application.Volatile. I'm assuming calculation is set as Automatic.
 
Upvote 0
Here is my code....namerange shift is another function that I have used to select cells in a named range that are to the left or right of the current column as for example, when using Excel's SUM function, excel tried to SUM the entire name range.

Code:
Function CalculateAverageSubscribersEOP(ByRef EOPSubscriberRange As Range, ByVal ThisCol As Double) As Double
  
Dim TestNumber As Boolean
Dim SubRangeValMinus1
Dim SubRangeVal
Dim SubRangeValPlus1

SubRangeValMinus1 = Range(EOPSubscriberRange.Address).Cells(1, ThisCol - 1).Value
SubRangeVal = Range(EOPSubscriberRange.Address).Cells(1, ThisCol).Value
SubRangeValPlus1 = Range(EOPSubscriberRange.Address).Cells(1, ThisCol + 1).Value

TestNumber = Application.WorksheetFunction.IsNumber(NameRangeShift(EOPSubscriberRange, -1, ThisCol))

If TestNumber Then
    CalculateAverageSubscribersEOP = (SubRangeVal + SubRangeValMinus1) / 2
Else
    CalculateAverageSubscribersEOP = (SubRangeVal * SubRangeVal / SubRangeValPlus1 + SubRangeVal) / 2
End If

End Function

Thanks
 
Upvote 0
Tell how exactly you tried Application.Volatile. I'm assuming calculation is set as Automatic.
 
Upvote 0
I used application.volatile straight after the function at the top of the code, before I dimensioned anything. Automatic calculation is turned on.

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,617
Messages
6,120,541
Members
448,970
Latest member
kennimack

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