Results 1 to 2 of 2

Thread: Add a range to a selection

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    7

    Add a range to a selection

    Hi,

    I want to add a new selection to a previously defined selection.

    I am very bad at using range object even after studying its usage. Here is what I am trying:

    Range(Selection, ActiveCell, ActiveCell.Offset(5, 0)).Select

    And obviously this is not working for me.
    I found people using multiple selections in a range but they are all using cell addresses separated with commas. example: range(A1:B10, C2:E9, G2). I don't have such specific cell addresses with me. How do we add multiple selections in a range without using the cell addresses?

    Please help me out.

    Thanks
    Last edited by mobilepoker; Jun 6th, 2021 at 07:28 AM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Add a range to a selection

    you can add a selection to a range like
    Code:
    Set cel = Range("B6")
    Set cel = Union(cel, Selection)
    cel.select
    but it would be hard to have an active cell that is not included in the selection, or to have 2 selections at the same time, but i may be missing something in your scenario, unless you save the range object between selecting the first selection and the second
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width