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.
 
Hello NoSparks

D23177E5-A48B-4BF0-94A9-C17E0152C179.png


UT = V
IB = I
P = P
R = R

UT cell = B5
IB cell = B6
P cell = F5
I have not made it for R, cause I don't need it into voltage drop calculates.
Thank you.
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Any reason you don't want to just do this ?

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
    ElseIf IsNumeric(ws.Range("B6").Value) And ws.Range("B6").Value <> "" And _
            IsNumeric(ws.Range("F5").Value) And ws.Range("F5").Value <> "" Then
        UT = Round(ws.Range("F5").Value / ws.Range("B6").Value, RN)
    End If
    
End Function

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
    ElseIf IsNumeric(ws.Range("B5").Value) And ws.Range("B5").Value <> "" And _
            IsNumeric(ws.Range("F5").Value) And ws.Range("F5").Value <> "" Then
        IB = Round(ws.Range("F5").Value / ws.Range("B5").Value, RN)
    End If

End Function

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
    ElseIf IsNumeric(ws.Range("B5").Value) And ws.Range("B5").Value <> "" And _
            IsNumeric(ws.Range("B6").Value) And ws.Range("B6").Value <> "" Then
        P = Round(ws.Range("B5").Value * ws.Range("B6").Value, RN)
    End If
    
End Function
 
Upvote 0
Solution
Hello Alex

It actually solved the problem, but the only thing is - that I think it was easier to return functions instead.

1640810100114.png

If I now have these values that need to be calculated and I need to avoid circular reference. Here, not all fields are filled in, I have to find the results myself - with calculations. Any idea to fix it?
It must, of course, return the correct formula first.

Thanks for the help, really appreciate your kindness!
 
Upvote 0
I was hoping @NoSparks might respond since I think he is might be more familiar with what you are trying to do.
I would need multiple examples using your format above of what you are trying to do.

I am not sure a Function would work in the sense of that your can't put a function in multiple boxes if some are manually input numbers.
I would think you would need a button to say calculate now, since you always need to enter at least say 2 values.

Also if you treat the 3 version of E = IR as one formula, how many formulas does your grid actually require.
Is each row related to one formula ?
 
Upvote 0
Hello Alex

Sorry for the late reply, but I think I'm trying to do it in a new way and then I have to ask if there are any problems along the way.
Thanks for the help and happy new year.
 
Upvote 0

Forum statistics

Threads
1,215,034
Messages
6,122,782
Members
449,095
Latest member
m_smith_solihull

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