Fordraiders
asked on
add 2 columns of listbox from another listbox
vba excel 2010 userform listbox
Trying to loop through listbox1 and add the first 2 columns to listbox2
Listbox1 has 42 columns
Listbox2 has 2 columns
Dim iIndex
Dim s As Long, j As Long, k As Long
With ListBox1
s = .ListIndex
ListBox2.AddItem .List(s, 0), 0
ListBox2.AddItem .List(s, 1), 0
j = ListBox2.ListCount - 1
For k = 1 To .ColumnCount - 1
ListBox2.List(j, k) = .List(s, k)
Next k
End With
This is only adding one row and not completely right
Thanks
fordraiders
Trying to loop through listbox1 and add the first 2 columns to listbox2
Listbox1 has 42 columns
Listbox2 has 2 columns
Dim iIndex
Dim s As Long, j As Long, k As Long
With ListBox1
s = .ListIndex
ListBox2.AddItem .List(s, 0), 0
ListBox2.AddItem .List(s, 1), 0
j = ListBox2.ListCount - 1
For k = 1 To .ColumnCount - 1
ListBox2.List(j, k) = .List(s, k)
Next k
End With
This is only adding one row and not completely right
Thanks
fordraiders
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi
They are 0-based array so if you want 13 columns you have to give 12 as parameter on the redim
on your example the 30pt col is the 11th not the 13th
Regards
They are 0-based array so if you want 13 columns you have to give 12 as parameter on the redim
on your example the 30pt col is the 11th not the 13th
Regards
ASKER
thanks
ASKER
I have a weird question: i expanded the data needed to , I THINK column 13
UserForm2.ListBox52.Clear
Dim arrListBxList As Variant
arrListBxList = ListBox32.List
ReDim Preserve arrListBxList(UBound(arrLi
ListBox52.List = arrListBxList
45 pt;60 pt;0 pt;0 pt;0 pt;0 pt;0 pt;0 pt;0 pt;0 pt;30 pt;0 pt;0 pt
I had to set my column count 13 and the column widths as above..
i need to see, columns 0,1,10...
I dont understand the math of 13 in the code...
Thanks very much !!