Results 1 to 2 of 2

Thread: [SOLVED:Excel] Selecting non-adjacent cells with Union

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2011
    Posts
    4

    Resolved [SOLVED:Excel] Selecting non-adjacent cells with Union

    I need to make multiple selections of non-adjacent cells in Excel:

    Union(Range(Cells(7, 2), Cells(17, 2)), Range(Cells(7, 4), Cells(17, 4))).Select

    What makes my problem tricky is that the number of ranges I need to pass through the union method varies depending on other information in the file determined at runtime. Sometimes I will select 2 ranges, other times 3 ranges, etc. I tried to put the ranges in a string variable:

    InStr="Range(Cells(7, 2), Cells(17, 2)), Range(Cells(7, 4), Cells(17, 4))"
    Union(InStr).Select

    But it appears that you can only pass range type variables through the union method. Does anyone have any idea on how I can program this without using brute force? I don't have to use union, I just use this since this is what I know to use for non-adjacent selections.

    Thanks in advance!
    Last edited by kinch956; Sep 1st, 2011 at 07:37 PM. Reason: Solved Issue

  2. #2

    Thread Starter
    New Member
    Join Date
    Apr 2011
    Posts
    4

    Resolved Re: [Excel] Selecting non-adjacent cells with Union

    I figured it out! I create two range variables. Then in a for or while loop I put each new range I want to eventually select in one of the range variables. Then as I find more and more ranges that I eventually want to select, I put the new range in one of the range variables and then I use the union method to do the union of what is in the main range variable with the new range that was just found.

Tags for this Thread

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