+ Reply to Thread
Results 1 to 4 of 4

Range problems...

Hybrid View

Guest Range problems... 03-24-2005, 02:06 PM
Guest Re: Range problems... 03-24-2005, 03:06 PM
Guest Re: Range problems... 03-24-2005, 03:06 PM
Guest Re: Range problems... 03-24-2005, 03:06 PM
  1. #1
    Mark Bigelow
    Guest

    Re: Range problems...

    The problem is that you're not properly using the Range data type and
    the Set keyword. If you use MyRange as a Range object, it's only going
    to apply to the specific sheet and range you used when you set it
    (ActiveSheet by default). To generalize the range for all sheets,
    there are (at least) two ways to do it:

    First:
    ---------------
    Dim MyRange as String

    MyRange = "B19:I26"
    Worksheet(<Whatever>).Range(MyRange).Select
    ---------------

    Second:
    ---------------
    Dim MyRange as Range

    Set MyRange = Range("B19:I26")
    Worksheet(<Whatever>).Range(MyRange.Address).Select
    ---------------

    The first is probably best because you save a little memory (especially
    if it's in a loop).

    Let me know if that doesn't make sense.
    Mark

    Neil wrote:
    > Hello All,
    >
    > If I have the following code:
    >
    > -------------------
    > Dim MyRange As Range
    >
    > Set MyRange = "B19:I26"
    > -------------------
    >
    > How can i get the Active worksheet (or any other worksheet) to select

    that
    > same range.
    >
    > ActiveSheet.Range(MyRange).Select
    >
    > wont work because Range expects 2 arguments.
    >
    > TIA,
    >
    > Neil.



  2. #2
    K Dales
    Guest

    Re: Range problems...

    A few other points:

    If you are talking about the active worksheet, you can just do Range().Select

    Unless you need to re-use your range address, you can specify it directly,
    e.g. Range("B19:I26").Select.

    Finally, you will not be able to use Range.Select on a sheet if it is not
    active; if ot talking about the active sheet, before you select you need to
    activate the sheet, e.g.:
    Worksheets("Sheet2").Activate
    Worksheets("Sheet2").Range("B19:I26").Select

    "Mark Bigelow" wrote:

    > The problem is that you're not properly using the Range data type and
    > the Set keyword. If you use MyRange as a Range object, it's only going
    > to apply to the specific sheet and range you used when you set it
    > (ActiveSheet by default). To generalize the range for all sheets,
    > there are (at least) two ways to do it:
    >
    > First:
    > ---------------
    > Dim MyRange as String
    >
    > MyRange = "B19:I26"
    > Worksheet(<Whatever>).Range(MyRange).Select
    > ---------------
    >
    > Second:
    > ---------------
    > Dim MyRange as Range
    >
    > Set MyRange = Range("B19:I26")
    > Worksheet(<Whatever>).Range(MyRange.Address).Select
    > ---------------
    >
    > The first is probably best because you save a little memory (especially
    > if it's in a loop).
    >
    > Let me know if that doesn't make sense.
    > Mark
    >
    > Neil wrote:
    > > Hello All,
    > >
    > > If I have the following code:
    > >
    > > -------------------
    > > Dim MyRange As Range
    > >
    > > Set MyRange = "B19:I26"
    > > -------------------
    > >
    > > How can i get the Active worksheet (or any other worksheet) to select

    > that
    > > same range.
    > >
    > > ActiveSheet.Range(MyRange).Select
    > >
    > > wont work because Range expects 2 arguments.
    > >
    > > TIA,
    > >
    > > Neil.

    >
    >


+ 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