Are Named Arguments not supported in VBA?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,535
Office Version
  1. 365
Platform
  1. Windows
I came across this page that explains Named Arguments.


But I can't get it to work. Here's the little test function I wrote:

VBA Code:
Function TestArgs(p1, p2, p3)
Debug.Print Time & " p1 = '" & p1 & "', p2 = '" & p2 & "', p3 = '" & p3 & "'"
End Function

I tried calling it like this =testargs(p1:=1, p2:=2, p3:=3), but Excel takes p1, p2, & p3 to be cell addresses and it gets an error. I tried renaming the parameters to something that cannot be a cell address, but I got the same error.

Is this just a VB.Net feature?
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I think I found the answer. Apparently, this feature only works within VBA. If I call that test function from the Immediate window, it works:

1677397556891.png


(sigh)
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,900
Members
449,194
Latest member
JayEggleton

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