+ Reply to Thread
Results 1 to 4 of 4

Not able to execute a function - ByRef argument type mismatch

  1. #1
    Registered User
    Join Date
    01-10-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    11

    Not able to execute a function - ByRef argument type mismatch

    Team,

    I am trying to execute a function whose input has a range and the out put of the functions is also a range having same number of rows.

    When i keep a breakpoint at the beginning of funtion i got an error - ByRef argument type mismatch

    Below is the pseudocode

    Please Login or Register  to view this content.
    One more Q - When i pass a range as input to fucntion(B3 to D20), can i refer to the content in the range assuming its an array. Range(1,1) = B3, Range(RangeRowCount, RangeColumnCount) = D20

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Not able to execute a function - ByRef argument type mismatch

    Hello dax2ib,

    When arguments are passed by reference, they must have been declared using the DIM statement or be assigned to objects that already exist, like a Range on a worksheet. All Ranges objects are passed as 2-D arrays even if it only a single cell. The important thing to remember is a Range is an Object array. This means you will have full access to all the methods and properties of a Range object. A standard array will only contain values, not objects.

    You can convert a Range into a standard 2-D array easily. See the code below:
    Please Login or Register  to view this content.
    It is important to add the Value property to the Range in this case. This will tell VBA to convert the Range to an array. You can assign a 2-D Array to a range also, just reverse the arguments. This will overwrite formulas but not cell formatting.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,963

    Re: Not able to execute a function - ByRef argument type mismatch

    1.
    Please Login or Register  to view this content.
    2. You can't do: VarA(1) = VarA(2) = VarB(1) = VarB(2) = VarC(1) = VarD(2) = 1 in VBA; each array's element must be initialized separately.
    Ben Van Johnson

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Not able to execute a function - ByRef argument type mismatch

    how do you call the function?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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