Getting multi column data into a Listbox from a 2D Array

Hi

I'm struggling to get some data from a 2D array into a listbox. I've included a code snippet. At the moment I'm only getting the first column populated.

The code below opens a second Workbook
The 2D array is called filterManagerWB and 5 elements are populated for each sheet.
The idea is to get 5 columns in the listbox with the number of rows dependant on number of sheets.

        Set filterManagerWB = Workbooks.Open(filenamePath)
        SheetCount = filterManagerWB.Sheets.Count
        ReDim filterInfo(1 To SheetCount, 1 To 5)
        
        For i = 1 To SheetCount
            filterInfo(i, 1) = filterManagerWB.Sheets(i).Name
            filterInfo(i, 2) = filterManagerWB.Sheets(i).Cells(1, 2).Value   'Contains Created By
            filterInfo(i, 3) = filterManagerWB.Sheets(i).Cells(2, 2).Text      'Contains Created Date
            filterInfo(i, 4) = filterManagerWB.Sheets(i).Cells(3, 2).Value   'Contains Updated By
            filterInfo(i, 5) = filterManagerWB.Sheets(i).Cells(4, 2).Text      'Contains Updated Date
        Next i
        
        lstFilterList.List = sheetNames

Open in new window


I'm stuck how to populate the listbox properly
PJ0302917Asked:
Who is Participating?
 
NorieVBA ExpertCommented:
This might be a stupid question, but what's the ColumnCount property of the listbox set to?

It should be set to the no of columns of data you have, which I think should be 5 in this case.
0
 
NorieVBA ExpertCommented:
Which array are trying to you populate the listbox with?

Is it sheetNames, which I assume is declared and populated elsewhere, or filterInfo which you are populating in the posted code?
0
 
PJ0302917Author Commented:
Its Filter Info
So the data looks something like this

SheetName1 |Created By Data|Created By Date |Updated By|Updated By Date
SheetName2 |Created By Data|Created By Date |Updated By|Updated By Date
SheetName3 |Created By Data|Created By Date |Updated By|Updated By Date
SheetName4 |Created By Data|Created By Date |Updated By|Updated By Date
SheetName5 |Created By Data|Created By Date |Updated By|Updated By Date

The Created / Updated data is taken from the first few cells on each worksheet
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
NorieVBA ExpertCommented:
Do either of these work?
 lstFilterList.List = filterInfo

' or

 lstFilterList.List = Application.Transpose(filterInfo)

Open in new window

0
 
PJ0302917Author Commented:
Thanks for the help, I've just tried both

lstFilterList.List = filterInfo gives me a single column (in the listbox) of SheetNames. E.g

SheetName1 |
SheetName2 |
SheetName3 |
SheetName4 |
SheetName5 |

lstFilterList.List = Application.Transpose(filterInfo) gives me all the data for one element in the array (but still in one column of the listBox)

SheetName1         |
Created By Data.  |
Created By Date.  |
Updated By.          |
Updated By Date |
0
 
PJ0302917Author Commented:
Thats it, code was right originally, just didn't know about that property on the Listbox.

Thanks a lot for helping me
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.