VBA function run-time error 28

Nervatos

New Member
Joined
Dec 19, 2021
Messages
32
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hello there

I have tried to get this to work, but it comes with this error: Run-time error '28': Out of stack space

VBA Code:
Private Function UT() As Double
    Application.Volatile
    Dim ws As Worksheet
    Set ws = Worksheets(Sh)

    If IsNumeric(ws.Range("B5").Value) And ws.Range("B5").Value <> "" Then
        UT = ws.Range("B5").Value
        Exit Function
    ElseIf P() > 0 And IB() > 0 Then
        UT = Round(P() / IB(), RN)
        Exit Function
    End If
End Function
VBA Code:
Private Function IB() As Double
    Application.Volatile
    On Error GoTo 0
    Dim ws As Worksheet
    Set ws = Worksheets(Sh)

    If IsNumeric(ws.Range("B6").Value) And ws.Range("B6").Value <> "" Then
        IB = ws.Range("B6").Value
        Exit Function
    ElseIf P() > 0 And UT() > 0 Then
        IB = Round(P() / UT(), RN)
        Exit Function
    End If
End Function
VBA Code:
Private Function P() As Double
    Application.Volatile
    Dim ws As Worksheet
    Set ws = Worksheets(Sh)

    If IsNumeric(ws.Range("F5").Value) And ws.Range("F5").Value <> "" Then
        P = ws.Range("F5").Value
        Exit Function
     ElseIf UT() > 0 And IB() > 0 Then
        P = Round(UT() * IB(), RN)
        Exit Function
    End If
End Function

My error comes in this line: ElseIf P() > 0 And IB() > 0 Then
Coming in Function UT.

The error is comes then some value is missing. I have tried to search for the error, but all I found is Application.EnableEvents = False and Application.EnableEvents = True. I have tried to put it in this Functions, but still same error. So hope You guys can handle it, cause I can't.
Thank you.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I am not sure how you are using this or what you are trying to do.
But the functions are effectively a circular reference.

If the function your start with eg IB is called and IB has a value it only run once, even if both UT & P are text.

If IB is text then it recursively runs the other 2.
If both the other 2 are text then it will give you your error.
If only 1 of the the other 2 are text it seems to be depend on the order with one being recursively running a certain a number of times and the other doing a runaway recursion and also giving you, your error.
 
Upvote 0
Hello Alex

I'm trying to make Ohms Law, so it's only numbers.

Do you know how to solve this kind of circular reference and still given the values their owns function?
Thanks for your reply.
 
Upvote 0
How are you calling the function(s) ? Are you just calling one of them ?
Each function has a line similar to this one in function P: If IsNumeric(ws.Range("F5").Value) And ws.Range("F5").Value <> "" Then
What is the calculation meant to be if this line fails and it moves on to the ElseIf ?
Is there any validation on B5, B6 & F5 to force them to be Numeric ?
 
Upvote 0
Hello Alex

I calling it like this:
VBA Code:
Public Function SFUT() As String
    Application.Volatile
    Call UT
    SFUT = UT
End Function

I have no validation for the cells, only check it's a number and the cell has value.

I need to get two values, to return the last value. So if B5 (UT) and F6 (P) has value, then I can find B6 (IB). Same if F6 (P) and B6 (IB) then I can get B5 (UT). I have other calculations, so then I just use UT(), IB() and P() to get other values.
If there is no value for some of them, it should just return 0

Hope you can understand my bad English :)
 
Upvote 0
So specifically in Call UT,
if UT has a value it will return that.
If UT does not have a value then you need both IB & P to be populated to return a value else return 0.
Is that correct ?

If it is then I think the UT function needs to check B6 & F5 directly not by calling their function.
 
Upvote 0
Hello Alex

Yes that's right, and same for both IB & P, they also need two values to return value.
 
Upvote 0
Which is UT, Which is IB, Which is P, and which is in what cell ?

2021-12-28 06_21_26-Window.png
 
Upvote 0

Forum statistics

Threads
1,215,563
Messages
6,125,565
Members
449,237
Latest member
Chase S

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