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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,686
Show the VBA please. And tell how exactly you tried Application.Volatile. I'm assuming calculation is set as Automatic.
 

soteman2005

New Member
Joined
Nov 24, 2005
Messages
32
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
 

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,686
Tell how exactly you tried Application.Volatile. I'm assuming calculation is set as Automatic.
 

soteman2005

New Member
Joined
Nov 24, 2005
Messages
32
I used application.volatile straight after the function at the top of the code, before I dimensioned anything. Automatic calculation is turned on.

Thanks
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,802
Messages
5,833,755
Members
430,230
Latest member
Doug G

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
Top