PDA

View Full Version : Excel userform ListBox multicolumn



rahul_r79
11-25-2009, 04:00 PM
Hi
I am new in VBA and trying to get a multicolumn in my ListBox in Excel Userform ,If i select a particular sheet.Presently I can Select a sheet
but in the List box it is putting all the data in one List

Bob Phillips
11-25-2009, 04:10 PM
Private Sub CommandButton1_Click()
Dim i As Long
Dim wsMyWks As String
Dim nRow As Long
Dim mRow As Range

wsMyWks = ComboBox1.Value

With Me.ListBox1

.BoundColumn = 1
.ColumnCount = 4
.TextColumn = True

nRow = Worksheets(wsMyWks).Range("A65536").End(xlUp).Row
For Each mRow In Worksheets(wsMyWks).Rows("1:" & nRow)

.AddItem mRow.Cells(1, 1).Value
For i = 2 To 7

.List(.ListCount - 1, i - 1) = mRow.Cells(1, i).Value
Next i
Next mRow

End With

MsgBox "Paste your code to get info from userform to worksheet here"

End Sub

rahul_r79
11-25-2009, 10:08 PM
You are Genius, I was trying to do this from last 2 whole days :banghead: and you did it in :clap: half an hour

Aussiebear
11-29-2009, 12:08 AM
Oh I don't think it took him that long.