JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,691
- Office Version
- 365
- Platform
- Windows
I am working on a UDF with several keyword parameters that I am passing from Excel as a ParamArray. To keep the main UDF simpler, I would like to pass the entire ParamArray to a subroutine for processing. I can't get it to work.
Here's what I've tried:
When I try to run this, I get a Compile Error on the call to the subroutine saying that it is "Invalid parameter use".
I've tried it with and without the parentheses.
Can this be done? How?
Here's what I've tried:
Code:
' This is the main UDF as called from Excel.
Public Function Main(P1 As Range, P1 As Range, ParamArray PArgs()) As Variant
' Define and initialize the ParamArray variables
Dim PA1 As Single: PA1 = 100
Dim PA2 As Single: PA2 = 0
Dim PA3 As String: PA3 = "Off"
. . .
' Call the subroutine to process the ParamArray string (PArgs).
' Pass the variables that will be set by the ParamArray string ByRef
' so the subroutine can change them if necessary.
If PACheck(PA1, PA2, PA3, PArgs()) Then
Main = CVErr(xlErrValue): Exit Function 'If errors, exit
End If
. . .
End Function
'
Public Function PACheck(ByRef PA1, ByRef PA2, ByRef PA3, _
ByRef PArgs()) As Boolean
' Run through the ParamArray parameters, check for errors, and set the values
. . .
End Function
When I try to run this, I get a Compile Error on the call to the subroutine saying that it is "Invalid parameter use".
I've tried it with and without the parentheses.
Can this be done? How?