+ Reply to Thread
Results 1 to 5 of 5

Noncontiguous range with Range(Cells(r,c),Cells(r2,c2),Cells(r3,c3)...) ?

  1. #1
    Forum Contributor
    Join Date
    08-25-2014
    Location
    Pennsylvania, US
    MS-Off Ver
    Windows '16
    Posts
    165

    Noncontiguous range with Range(Cells(r,c),Cells(r2,c2),Cells(r3,c3)...) ?

    An analogy:

    Range("A1:E1") = Range(Cells(1,1),Cells(1,5))
    as
    Range("A1:C1,E1:G1,I1:L1") = ???

    In other words, how/can I refer to noncontiguous ranges with Range(Cells(variable,variable),Cells(var,var),Cells(var,var)...)? Thanks!

  2. #2
    Forum Contributor
    Join Date
    09-28-2014
    Location
    harbin,china
    MS-Off Ver
    2007
    Posts
    162

    Re: Noncontiguous range with Range(Cells(r,c),Cells(r2,c2),Cells(r3,c3)...) ?

    maybe
    union(range(cells(1,1),cells(1,3)),range(cells(1,"e"),cells(1,"g")),range(cells(1,"I"),cells(1,"L")))

  3. #3
    Forum Contributor
    Join Date
    01-08-2016
    Location
    Cagayan De Oro City, Philippines
    MS-Off Ver
    2013
    Posts
    152

    Re: Noncontiguous range with Range(Cells(r,c),Cells(r2,c2),Cells(r3,c3)...) ?

    Hi

    You need to know that its quite a pain working with non contiguous blocks of data take a look below......

    Capture.PNG


    You cannot directly directly access each region, you have to go through a very undocumented part of excel called 'Areas'

    a Range is made of non contiguous Areas (not cells), each Area is a block of contiguous cells (or at least its better to think that way)

    the quickest way to put all these together into a single easy to use range is to paste the range into a new sheet which will put all the data together into an easy to use range, otherwise you need to track the areas which is a pain in the backside.........

    but Union like it was mentioned before is the easiest way to join with multiple ranges

    Paul S.
    Last edited by gbeats101; 01-10-2016 at 01:01 AM.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Noncontiguous range with Range(Cells(r,c),Cells(r2,c2),Cells(r3,c3)...) ?

    Union is a robust way to build discontinuous ranges.
    I agree that they have to be used with care.
    I disagree about documentation. The Area object is well documented, its simply a range object.

    Another way to get a discourteous range is
    Please Login or Register  to view this content.
    Last edited by mikerickson; 01-10-2016 at 01:25 AM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Contributor
    Join Date
    08-25-2014
    Location
    Pennsylvania, US
    MS-Off Ver
    Windows '16
    Posts
    165

    Re: Noncontiguous range with Range(Cells(r,c),Cells(r2,c2),Cells(r3,c3)...) ?

    Great, thanks for the ideas everyone!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Lock/Unlock range cells based on text value in other range cells
    By boboivan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-12-2014, 12:50 PM
  2. [SOLVED] Macro needed to clear cells in range based on value of cells in another range
    By msmith7113 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-05-2013, 12:32 AM
  3. [SOLVED] Copy noncontiguous range of cells to another sheet
    By Pavan Renjal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-29-2012, 07:57 AM
  4. [SOLVED] VBA Copy a range of cells values using the range of cells in a formula (which will change)
    By murtaep in forum Excel Programming / VBA / Macros
    Replies: 32
    Last Post: 06-05-2012, 07:59 AM
  5. Replies: 2
    Last Post: 05-31-2012, 05:37 AM
  6. Passing noncontiguous cells as a range argument
    By gathrawnca in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-06-2010, 12:19 AM

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