Results 1 to 19 of 19

2D array from non contiguous columns

Threaded View

nigelog 2D array from non contiguous... 02-02-2018, 05:31 AM
Norie Re: 2D array from non... 02-02-2018, 05:43 AM
jindon Re: 2D array from non... 02-02-2018, 05:43 AM
nigelog Re: 2D array from non... 02-02-2018, 06:05 AM
jindon Re: 2D array from non... 02-02-2018, 06:09 AM
nigelog Re: 2D array from non... 02-02-2018, 06:18 AM
Norie Re: 2D array from non... 02-02-2018, 06:23 AM
nigelog Re: 2D array from non... 02-02-2018, 06:27 AM
nigelog Re: 2D array from non... 02-02-2018, 06:50 AM
jindon Re: 2D array from non... 02-02-2018, 06:58 AM
nigelog Re: 2D array from non... 02-02-2018, 07:01 AM
nigelog Re: 2D array from non... 02-02-2018, 08:45 AM
jindon Re: 2D array from non... 02-02-2018, 08:48 AM
Greg M Re: 2D array from non... 02-06-2018, 07:31 PM
nigelog Re: 2D array from non... 02-07-2018, 08:14 AM
Greg M Re: 2D array from non... 02-09-2018, 09:21 PM
nigelog Re: 2D array from non... 02-12-2018, 12:46 PM
Greg M Re: 2D array from non... 02-12-2018, 09:15 PM
antonsachs Re: 2D array from non... 02-20-2022, 08:24 PM
  1. #1
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    2D array from non contiguous columns

    In an effort to try to not use named ranges on helper worksheets I would like to see if I can write to a 2D array and use the data in that to populate userforms. I have little knowledge of arrays and might be going the wrong way about it. This code will load two columns but not 3 or 4. I would also like to refer the columns by number rather than letter. Any pointers appreciated.

    Sub StoreRange()
        Dim MyArray() As String, asheet As Worksheet
        Dim iloop As Integer
        Dim x As Variant
        ReDim MyArray(0)
        Dim LastRow As Long
        Set asheet = ActiveSheet
        With asheet
         LastRow = .Range("a" & Rows.Count).End(xlUp).Row
        For Each x In .Range("a1:A" & LastRow, "e1:e" & LastRow).Cells
    
        'For Each x In .Range("a1:A" & LastRow, "e1:e" & LastRow, "j1:j" & LastRow, "n1:n" & LastRow).Cells
    
            MyArray(UBound(MyArray)) = x
            ReDim Preserve MyArray(UBound(MyArray) + 1)
        Next
        
        ReDim Preserve MyArray(UBound(MyArray))
    
        For iloop = LBound(MyArray) To UBound(MyArray)
            Debug.Print MyArray(iloop)
        Next
        End With
    End Sub
    sample attached
    Attached Files Attached Files
    Last edited by nigelog; 02-02-2018 at 08:11 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Create an array for filtered and non-contiguous columns
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-28-2015, 04:39 PM
  2. Copy contiguous columns and paste as non-contiguous
    By absconditus in forum Excel General
    Replies: 1
    Last Post: 12-29-2014, 03:17 AM
  3. [SOLVED] How to sum non-contiguous columns applied as a formula on contiguous cells
    By figo12 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 10-09-2013, 01:07 PM
  4. Copy and Paste an array (contiguous & non contiguous ranges)
    By Xrull in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-09-2010, 09:17 AM
  5. Copying non-contiguous columns to contiguous columns
    By Bob in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-09-2006, 10:54 PM
  6. filling array with non-contiguous range
    By koalabeer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-27-2005, 08:41 PM
  7. [SOLVED] change the 8th column in a not contiguous array
    By Spencer Hutton in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-20-2005, 01:07 PM

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