VBA Form - MultiColumn ListBox

iancook1982

New Member
Joined
Jun 14, 2010
Messages
13
Hi,
I am trying to populate a multicolumn listbox on a form from the same workbook as the form is in. Here's what I have.

'define ranges
Dim SourceData As Range
Dim FundCount As Range
Dim records As Integer
Worksheets("clientlist").Select
Range("S1").Select
Range(Selection, Selection.End(xlDown)).Select
Set SourceData = Selection
records = Selection.Count
Range("T1").Select
Range(Selection, Selection.End(xlDown)).Select
Set FundCount = Selection

Dim ListItems As Variant
Dim i As Integer
With Me.ClientList
.Clear
.ColumnCount = 2
ListItems = SourceData.Cells.Value
ListItems = Application.WorksheetFunction.Transpose(ListItems)
For i = 0 To records
.AddItem
.List(i, 0) = SourceData(i)
.List(i, 1) = FundCount(i)
Next i
End With

The first part sets the arrays, then the 2nd tries to fill the listbox. But it bugs out at:
.List(i, 0) = SourceData(i)

Can you help? What have I missed?

Thanks,
Ian.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
You don't appear to be using ListItems anywhere? Anyway, do you get a subscript out of range? This would be caused by SourceData having 2 dimensions so:

Code:
.List(i, 0) = SourceData(i+1,1)
 
Upvote 0
that's great. thanks.

I got it working with:

Dim List As Variant
Dim i As Integer
With Me.ClientList
.Clear
.ColumnCount = 2
List = SourceData.Cells.Value
List = Application.WorksheetFunction.Transpose(ListItems)
For i = 0 To records
.AddItem
.List(i, 0) = SourceData(i + 1, 1)
.List(i, 1) = FundCount(i + 1, 1)
Next i
End With


How do I populate column headers?

Thanks,
Ian.
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,854
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top