+ Reply to Thread
Results 1 to 4 of 4

Output 2D array into each table column

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Output 2D array into each table column

    Hi Guys,

    i have array and want to output to each listcolumn in listtable object.

    code:

    Sub test()
    
    Dim arrVar(0 To 2, 0 To 1) As Variant
    Dim lstTable As ListObject
    Dim i As Long
    
    Set lstTable = ActiveSheet.ListObjects(1)
    
    arrVar(0, 0) = 1
    arrVar(0, 1) = 2
    arrVar(1, 0) = "Paul"
    arrVar(1, 1) = "Luke"
    arrVar(2, 0) = "Magaj"
    arrVar(2, 1) = "Skywalker"
    
    For i = 1 To lstTable.ListColumns.Count
    
          If i = 1 or i = 3 then
               lstTable.ListColumns(i).DataBodyRange.Value = Application.Index(arrVar, 0, 1) '''here i am getting not proper data
          end if 
    
    Next i
    
    End Sub
    in line i can not handle outputting array:
    lstTable.ListColumns(i).DataBodyRange.Value = Application.Index(arrVar, 0, 1)
    I have to have array in this shape because it is taken from recordset rows (rst.getrows property).
    I could populate recordset at once but sometimes i have to skip columns. So for example output only to column 1 and 3.

    Can anybody help?

    Best wishes,
    Jacek Antek
    Attached Files Attached Files
    Last edited by jaryszek; 07-03-2019 at 07:33 AM.

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,133

    Re: Output 2D array into each table column

    You've got the array the wrong way, try
    Sub test()
    
    Dim arrVar(0 To 1, 0 To 2) As Variant, x
    Dim lstTable As ListObject
    Dim i As Long
    
    Set lstTable = ActiveSheet.ListObjects(1)
    
    arrVar(0, 0) = 1
    arrVar(1, 0) = 2
    arrVar(0, 1) = "Paul"
    arrVar(1, 1) = "Luke"
    arrVar(0, 2) = "Magaj"
    arrVar(1, 2) = "Skywalker"
    
    For i = 1 To lstTable.ListColumns.Count
          lstTable.ListColumns(i).DataBodyRange.Value = Application.Index(arrVar, 0, i)
    Next i
    End Sub

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Output 2D array into each table column

    hi Fluff13,

    o wow thank you!
    Index is still confusing for me but it is very useful.

    Jacek

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,133

    Re: Output 2D array into each table column

    You're welcome & thanks for the feedback

+ 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. Copy paste from id to west column table data onto output sheet using vba
    By globalsourcing in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-13-2016, 02:13 PM
  2. [SOLVED] Array to embed formula and if number of output is met output Blank
    By ywang in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-29-2015, 02:34 AM
  3. VBA Output One Column of Array to Worksheet
    By bsamuels in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-30-2015, 06:04 PM
  4. Replies: 8
    Last Post: 09-20-2014, 10:47 AM
  5. Replies: 5
    Last Post: 04-02-2014, 01:28 PM
  6. [SOLVED] Use ComboBox value to reference table and dynamically output corresponding column data
    By numbnuts in forum Excel Programming / VBA / Macros
    Replies: 54
    Last Post: 05-29-2013, 11:01 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