+ Reply to Thread
Results 1 to 4 of 4

syntax - range name as a variable

  1. #1
    Peter Morris
    Guest

    syntax - range name as a variable



    I can select a named range like so :

    range ("range_01").select

    this works. but I want to make the selected range a variable like this:

    range_string = "range_01"
    range (range_string).select

    This gives me error messages "method range of object global failed"


    What is the correct syntax for doing this?



  2. #2
    Bob Phillips
    Guest

    Re: syntax - range name as a variable

    Works for me. Did you declare range_string as string?

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Peter Morris" <nospam.ple@se> wrote in message
    news:[email protected]...
    >
    >
    > I can select a named range like so :
    >
    > range ("range_01").select
    >
    > this works. but I want to make the selected range a variable like this:
    >
    > range_string = "range_01"
    > range (range_string).select
    >
    > This gives me error messages "method range of object global failed"
    >
    >
    > What is the correct syntax for doing this?
    >
    >




  3. #3
    Peter Morris
    Guest

    Re: syntax - range name as a variable


    "Bob Phillips" <[email protected]> wrote in message
    news:u1Ju8h%[email protected]...
    > Works for me. Did you declare range_string as string?



    Yes, I did.



  4. #4
    Dave Peterson
    Guest

    Re: syntax - range name as a variable

    You can only select a range if the worksheet that owns the range is active.

    And you can only select a worksheet if the workbook that owns the worksheet is
    active.

    So you can pepper your code with

    workbooks("book1.xls").activate
    workbooks("book1.xls").worksheets("sheet1").select
    workbooks("book1.xls").worksheets("sheet1").range("range_01").select

    or use

    application.goto _
    workbooks("book1.xls").worksheets("sheet1").range("range_01"), _
    scroll:=true '?

    ======
    And depending on where your code is (is it behind a worksheet?), you could have
    the problem because an unqualified range (range("range_01") belongs to the
    worksheet that holds the code.

    And that might not be where the range really is (and it blows up real good).


    Peter Morris wrote:
    >
    > I can select a named range like so :
    >
    > range ("range_01").select
    >
    > this works. but I want to make the selected range a variable like this:
    >
    > range_string = "range_01"
    > range (range_string).select
    >
    > This gives me error messages "method range of object global failed"
    >
    > What is the correct syntax for doing this?


    --

    Dave Peterson

+ 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