Is there a way to display a function call with all parameters resolved?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,532
Office Version
  1. 365
Platform
  1. Windows
I have some function calls that have rather complicated parameters. Some are the result of calculations. Others are references to table cells that are, themselves, the result of calculations.

Here's one example:
VBA Code:
=BINOM.DIST([@X1]-1,[@N1]-1,ProbWin,[@Cum1])*ProbWin

When debugging, it would be helpful to be able to see the actual values that are being passed. I have a UDF that will display in a cell the text of the expression exactly like it is above. Is there a way that I can display the actual parameters that the function sees? In the above case, that might look like this:
VBA Code:
=BINOM.DIST(2,5,0.5,False)*0.5
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
if the question is concerning a excel formula in your sheet and not in VBA, you can use the Formula>evaluate on the ribbon.
With that one, you see step by step your formula calculating and the values, you asked for.
 
Upvote 0
if the question is concerning a excel formula in your sheet and not in VBA, you can use the Formula>evaluate on the ribbon.
With that one, you see step by step your formula calculating and the values, you asked for."
I should have mentioned that I do know about Evaluate. It's very helpful for a one-off evaluation. What I was looking for was text string in a nearby cell that showed the actual expression with all variables resolved.

I guess I'll have to "assemble" it manually, like:

VBA Code:
="BINOM.DIST(" & [@X1]-1 & ", " & [@N1]-1 & ", " & ProbWin & ", " & [@Cum1] & ")*" & ProbWin

That works, but it does not update if I edit the source expression.
 
Upvote 0
If that's the only function you have, why not encapsulate it in a variant UDF and have an optional boolean flag argument as the last parameter of the UDF which will indicate whether you want to return the actual function return value or the individual resolved parameters.

Something like this :
VBA Code:
Function BINOM_DIST( _
        number_s As Double, _
        trials As Double, _
        probability_s As Double, _
        cumulative As Boolean, _
        probwin As Double, _
        Optional ByVal ResolvedArguments As Boolean _
    ) As Variant

    BINOM_DIST = CDbl(WorksheetFunction.BINOM_DIST(number_s, trials, probability_s, cumulative) * probwin)
 
    If ResolvedArguments Then
        'Resolved arg values by position:
        'BINOM_DIST = "=BINOM_DIST(" & number_s & "," & trials & "," & probability_s & "," & cumulative & "," & probwin & ")"
 
        'Or full named arguents:
        BINOM_DIST = "=BINOM_DIST(" & _
                                    "number_s:=" & number_s & ", " & _
                                    "trials:=" & trials & ", " & _
                                    "probability_s:=" & probability_s & ", " & _
                                    "cumulative:=" & cumulative & ", " & _
                                    "probwin:=" & probwin & "," & ")"                           
                       
    End If

End Function

So, when the UDF is used in a worksheet cell, and depending on the last optional Boolean argument (Default value = FALSE)

This:
=BINOM_DIST(2,5,0.5,FALSE,0.5)
Will return:
0.15625

An this:
=BINOM_DIST(1, 3, 0.5, FALSE, 0.5,TRUE)
Will return the text string:
=BINOM_DIST(number_s:=1, trials:=3, probability_s:=0.5, cumulative:=False, probwin:=0.5,)
 
Last edited:
Upvote 0
Solution
If that's the only function you have, why not encapsulate it in a variant UDF and have an optional boolean flag argument as the last parameter of the UDF which will indicate whether you want to return the actual function return value or the individual resolved parameters.

Something like this: [actual code above]

So, when the UDF is used in a worksheet cell, and depending on the last optional Boolean argument (Default value = FALSE)

This:
=BINOM_DIST(2,5,0.5,FALSE,0.5)
Will return:
0.15625

An this:
=BINOM_DIST(1, 3, 0.5, FALSE, 0.5,TRUE)
Will return the text string:
=BINOM_DIST(number_s:=1, trials:=3, probability_s:=0.5, cumulative:=False, probwin:=0.5,)

I actually thought about something like this, but was too lazy to work out all the details. You are right that I don't need this facility very often, so taking the trouble to set up a UDF like this might just be worth it.

Thanks for taking the time to work it out. ??
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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