+ Reply to Thread
Results 1 to 5 of 5

select method of range class failed error

  1. #1
    Registered User
    Join Date
    09-07-2007
    Posts
    43

    select method of range class failed error

    I have different variables that I'm using to define ranges within different sheets. Whenever I switch from Sheet A to Sheet B, however, and then try to select a range in Sheet A by the name that I gave it in the vba, I get the "select method of range class failed error".

    I assume it has something to do with the fact that I'm giving different ranges in different sheets names, and then referring back to them from different sheets. Is there a way to define the name of the range so that it doesn't disappear once I switch to a different sheet? I just put

    Dim a As Range

    where "a" is the variable for the range that I set later in the code using "Set".

  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Without seeing your code, I would guess that you are not qualifying the range enough. You are probably using:
    Please Login or Register  to view this content.
    You should be using:
    Please Login or Register  to view this content.
    Or better yet:
    Please Login or Register  to view this content.
    HTH

    Jason

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

    This is a scoping problem. When you Dim in a private Sub or Function procedure, the variable will be destroyed once the procedure code is finished. To have a Range persist for the time Workbook is open, you should delcare a named Range. Use the Name property of the Range to assign it a name.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  4. #4
    Registered User
    Join Date
    09-07-2007
    Posts
    43
    I'm actually using

    Set a = Selection

    and it doesn't look like specifying the sheet before Selection works. I get the "object doesn't support this property or method" error. any other ideas?

  5. #5
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Did you read Leith's response? That would also definitely be an issue. Is this in a Private sub? If it is, the variable cannot be passed between procedures.

    Jason

+ 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