+ Reply to Thread
Results 1 to 3 of 3

Combining Multiple Range Values into a Single Array

Hybrid View

  1. #1
    Registered User
    Join Date
    03-03-2010
    Location
    Orlando, Florida
    MS-Off Ver
    Excel 2007
    Posts
    48

    Combining Multiple Range Values into a Single Array

    Hey,

    Say I have several ranges (A1:A3,A5:A10,A13:A20) with different values in each cell. The values will change on a weekly basis. I want to store these range values into a single array, so I can perform different tasks on the array. How would I go about doing this?

    Thanks.
    Last edited by fervorking; 01-19-2011 at 10:27 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Combining Multiple Range Values into a Single Array

    Hello fervorking,

    This UDF will take a range and convert it into a 1-D zero based array.
    Function MakeSingleArray(ByRef RngAreas As Range)
    
      Dim Cell As Range
      Dim Data As Variant
      Dim I As Long
      Dim Rng As Range
      
        ReDim Data(RngAreas.Cells.Count - 1)
        
          For Each Rng In RngAreas.Areas
            For Each Cell In Rng
              Data(I) = Cell.Value
              I = I + 1
            Next Cell
          Next Rng
       
        MakeSingleArray = Data
       
    End Function

    Example of Using the Macro
    This will convert the range shown into a single dimension array.
      Dim MyArray As Variant
    
        MyArray = MakeSingleArray(Range("A1:A3,A5:A10,A13:A20"))
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    03-03-2010
    Location
    Orlando, Florida
    MS-Off Ver
    Excel 2007
    Posts
    48

    Re: Combining Multiple Range Values into a Single Array

    Perfect. Thanks for the help.

+ 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