Populate list box

0 Agios

Well-known Member
Joined
Feb 22, 2004
Messages
570
Office Version
  1. 365
I have this code that shows columns "A".
I want to add "C" "D"

Private Sub UserForm_Initialize()
Dim arrlist As Variant
Dim LR As Long
With Worksheets("Data")
LR = .Range("A" & Rows.Count).End(xlUp).Row
'Set RNGP = .Range("A3:A30" & LR)
Set RNGP = .Range("A1:A20" & LR)

arrlist = RNGP.Value
ListBox1.List = WorksheetFunction.Transpose(arrlist)
End With
End Sub


Thanks
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
How many rows are there in each column?

Also, do you actually want to add the values, concatenate them or put use a 3 column listbox to display the values from all 3 columns?
Code:
Set rng = Worksheets("Data").Range("A1:A" & LR)
 
Listbox1.ColumnCount = 3
 
For Each cl In rng.Cells
 
       Listbox1.Additem cl.Value
       Listbox1.List(Listbox1.ListCount, 1) = cl.Offset(,2).Value
       Listbox1.List(Listbox1.ListCount, 2) = cl.Offset(,3).Value
Next cl
 
Upvote 0
How many rows are there in each column?

Also, do you actually want to add the values, concatenate them or put use a 3 column listbox to display the values from all 3 columns?
Code:
Set rng = Worksheets("Data").Range("A1:A" & LR)
 
Listbox1.ColumnCount = 3
 
For Each cl In rng.Cells
 
       Listbox1.Additem cl.Value
       Listbox1.List(Listbox1.ListCount, 1) = cl.Offset(,2).Value
       Listbox1.List(Listbox1.ListCount, 2) = cl.Offset(,3).Value
Next cl


Thanks Norie
I want to avoid concatenate, I tried this code and it doesnot work. I tried changing thing but I just cant get itto work.
 
Upvote 0
Change Listbox1.ListCount to Listbox1.ListCount -1.
 
Upvote 0

Forum statistics

Threads
1,224,558
Messages
6,179,512
Members
452,921
Latest member
BBQKING

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