+ Reply to Thread
Results 1 to 5 of 5

Passing Range Names as Arguments

  1. #1
    Registered User
    Join Date
    05-23-2012
    Location
    Colorado
    MS-Off Ver
    Excel 2010
    Posts
    3

    Passing Range Names as Arguments

    I have a number of named ranges in my workbook. I have a subroutine that I need to call repeatedly and need to pass one of these names as an argument to the subroutine. Here is my code right now:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    If it's not obvious, the idea is to work through a list of named ranges, sending each one individually to a subroutine called copyPaste. copyPaste first looks to another workbook (that will also contain a range with the exact same name), and copy the contents of that range onto the clipboard. Then it pastes these contents (as values) into the range in the active workbook. Conceptually pretty simple.

    Right now, I am stuck passing the range name as an argument. I am getting a run-time error "Application defined or object defined error".

    Can someone see what I am doing wrong?

    Thanks!

  2. #2
    Valued Forum Contributor
    Join Date
    05-07-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    354

    Re: Passing Range Names as Arguments

    I think if you add call keyword for the function call it will work ex:
    Please Login or Register  to view this content.
    or
    remove the parenthesis for the arguments ex:
    Please Login or Register  to view this content.
    Regards,
    Vandan

  3. #3
    Registered User
    Join Date
    05-23-2012
    Location
    Colorado
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Passing Range Names as Arguments

    Thank you, but neither of these is the problem. I believe that this is a typing problem. I'm not able to match the type of the argument to the type of the parameter. I'm trying to pass these as a Range type, but what I am doing is not working. Not sure if I need to choose a different type or change the way that I am capturing/passing.

    Anyone else see what is wrong?

  4. #4
    Valued Forum Contributor
    Join Date
    05-07-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    354

    Re: Passing Range Names as Arguments

    That is interesting joatmOn. your code worked fine for me after the changes I posted above. Can you upload your file?

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

    Re: Passing Range Names as Arguments

    the first line of the called routine should be
    Please Login or Register  to view this content.
    instead of
    Please Login or Register  to view this content.
    since thisRange is a specific Range object and not the name of one. you do also need to either use Call or remove the parentheses when calling the routine.
    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