Results 1 to 3 of 3
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Preserving range in Excel (Excel97-SR2, ...)

    I'm stumped. For the life of me I can't write code to preserve the existing range of cells. In Word97 it's easy:

    <pre>dim rng as range
    set rng=selection.range
    </pre>


    This doesn't work in Excel.

    The help files examples all quote specific cells and ranges such as Range("A5") and the like.

    In my case, I have no idea where the user is when my macro is given control. Whatever cells were selected on entry, I want them to be selected when I exit.

    (The macro is building a chart, and at end, the chart area is selected. I really want to de-select the chart, and figure that preserving the cells range on entry is the neat, general-purpose solution.)

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Preserving range in Excel (Excel97-SR2, ...)

    Chris,
    From what you say, I think:
    Dim rngOriginal as Range
    set rngOriginal = selection
    should do it.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Preserving range in Excel (Excel97-SR2, ...)

    <pre> Dim rngOriginal as Range
    set rngOriginal = selection
    </pre>


    Perfect! Thank you for the fast response.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •