+ Reply to Thread
Results 1 to 6 of 6

How to define a Paramarray( ) with two arguments

Hybrid View

  1. #1
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Lightbulb How to define a Paramarray( ) with two arguments

    Hi Forum,

    I am planning to create a ParamArray with dual argument.. Dual argument means.. always 2/4/6.. parameter need to specify..
    if you look at SUMIFS function -- CriteriaRange1, Criteria1 and CriteriaRange2, Criteria2 are always in a set..
    Currently I am managing it with lbound to ubound step 2 method.. but I have strong believe, there must be some method to define dual/triple paramarray defining option..

    Function fCreateSQLString(ByVal strTableName As String, ParamArray varColumnName() As Variant) As String
        
        Dim intCounter          As Integer
        Dim strSQL              As String
        
        strSQL = "SELECT * FROM " & strTableName & " where "
        For intCounter = LBound(varColumnName) To UBound(varColumnName) Step 2
            strSQL = strSQL & varColumnName(intCounter) & " = """ & varColumnName(intCounter + 1) & """" & vbNewLine
        Next intCounter
        
        fCreateSQLString = strSQL
        
    End Function
    Formula: copy to clipboard
    fCreateSQLString("ExcelForum","UserName","Debraj","Section","VBA","Solved","No")


    I am just worried about that red section, how to declare it something like..

    ParamArray {varColumnName(),varWhereClause()} As Variant

    If you will try SumIfs function like =SUMIFS(E11:E20,F11:F20,D8,G11:G20) [last criteria parameter missing]
    excel will through error..

    So the query is "How to declare paramarray with dual argument"..

    any Input will be appreciated..
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: How to define a Paramarray( ) with two arguments

    Hi,

    I think you are stuck with the 'Step 2'.

    Per the following article:
    However, since the ParamArray accommodates an arbitrary number of arguments as defined by the caller, it must be the last of the arguments.
    http://www.tushar-mehta.com/publish_...ramArray.shtml

    This implies to me that there can only be one ParamArray in the function. You should probably generate an error in your function if the ParamArray input has the wrong number of arguments.

    ParamArray varColumnName() As Variant is the only syntax I've ever seen. Since 'Variant' is the default type 'as Variant' can be omitted, but I always include it anyway.

    Lewis
    Last edited by LJMetzger; 12-08-2015 at 11:44 AM.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: How to define a Paramarray( ) with two arguments

    Quote Originally Posted by Debraj Roy View Post
    Currently I am managing it with lbound to ubound step 2 method.. but I have strong believe, there must be some method to define dual/triple paramarray defining option..
    I agree with Lewis; there is no dual-paramarray. Just use the one ParamArray and test if it has an even number of elements (in your case) for the 1st dimension.

    Public Function fCreateSQLString(ByVal strTableName As String, ParamArray varColumnName() As Variant) As String
        
        Dim intCounter          As Integer
        Dim strSQL              As String
        
        If UBound(varColumnName) Mod 2 = 0 Then
            MsgBox "You've entered too few arguments for this function. ", vbExclamation, "Missing Argument: fCreateSQLString"
        Else
        
            strSQL = "SELECT * FROM " & strTableName & " where "
            For intCounter = LBound(varColumnName) To UBound(varColumnName) Step 2
                strSQL = strSQL & varColumnName(intCounter) & " = """ & varColumnName(intCounter + 1) & """" & vbNewLine
            Next intCounter
            
            fCreateSQLString = strSQL
        End If
        
    End Function
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: How to define a Paramarray( ) with two arguments

    Hi Lewis and AlphaFrog,

    Thanks for your input,
    however, if you look at SUMIFS function,
    ParamArray.png

    its showing two parameter after entering param argument section, so is this something to play in RegisterUDF section.. or this tooltip is designed is this way and working with single paramArray() only!

  5. #5
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: How to define a Paramarray( ) with two arguments

    Quote Originally Posted by Debraj Roy View Post
    this tooltip is designed is this way and working with single paramArray() only!
    I think I got your point.. Thanks AlphaFrog ..

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: How to define a Paramarray( ) with two arguments

    I can't speak to the actual code for SUMIFS, but do I know the tool tip text for a function is just text that can be anything; it isn't defined by the function's argument(s). If you do a web search for something like Excel UDF tooltip, there are several guides on how to make your own.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Getting compile error user-define type not define
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-07-2015, 07:22 AM
  2. keep getting a application define or object define runtime error
    By JRJLHJ1823 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-22-2015, 08:55 PM
  3. VBA Function ParamArray parameter drop-down
    By onidarbe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-16-2013, 03:05 PM
  4. optimise code -> subroutine to function (paramarray??!)
    By tozjerimiah in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-01-2011, 10:00 AM
  5. error 1004 application define or object define
    By jay11 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-11-2011, 04:09 AM
  6. Define named range where user can define size
    By nahousto in forum Excel General
    Replies: 4
    Last Post: 07-06-2009, 05:09 PM
  7. passing ParamArray to ParamArray
    By foxguy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-22-2009, 11:47 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1