TimdeBlaeij
07-14-2017, 12:56 AM
Hi,
I am working on a program which is supposed to put columns S to AO in a listbox. I get a error message when I try to add more than 10 colomns. Does anybody know how i can fix this?
Also my scroller for my listbox is way bigger than needed. it goes far beyond my last filled in row.
Also i would like my top row to be visivle at all times when scrolling trough the listbox since it defines the rows. Anybody got something for these things too?
~Couple of things that you might want to know~
-All the colomns are equally long
- The length of colomn S is calculated with the code:
lenght_columns = Range("S2").End(xlDown).Row
-lsb1 = listbox1
This is my code:
Private Sub CommandButton1_Click()
lenght_columns = Range("S2").End(xlDown).Row
For i = 1 To lenght_columns
Lsb1.ColumnCount = 22
Lsb1.AddItem
Lsb1.List(i - 1, 0) = Cells(i, 19)
Lsb1.AddItem
Lsb1.List(i - 1, 1) = Cells(i, 20)
Lsb1.AddItem
Lsb1.List(i - 1, 2) = Cells(i, 21)
Lsb1.AddItem
Lsb1.List(i - 1, 3) = Cells(i, 22)
Lsb1.AddItem
Lsb1.List(i - 1, 4) = Cells(i, 23)
Lsb1.AddItem
Lsb1.List(i - 1, 5) = Cells(i, 24)
Lsb1.AddItem
Lsb1.List(i - 1, 6) = Cells(i, 25)
Lsb1.AddItem
Lsb1.List(i - 1, 7) = Cells(i, 26)
Lsb1.AddItem
Lsb1.List(i - 1, 8) = Cells(i, 27)
Lsb1.AddItem
Lsb1.List(i - 1, 9) = Cells(i, 28)
Lsb1.AddItem
Lsb1.List(i - 1, 10) = Cells(i, 29)
Lsb1.AddItem
Lsb1.List(i - 1, 11) = Cells(i, 30)
Lsb1.AddItem
Lsb1.List(i - 1, 12) = Cells(i, 31)
Lsb1.AddItem
Lsb1.List(i - 1, 13) = Cells(i, 32)
Lsb1.AddItem
Lsb1.List(i - 1, 14) = Cells(i, 33)
Lsb1.AddItem
Lsb1.List(i - 1, 15) = Cells(i, 34)
Lsb1.AddItem
Lsb1.List(i - 1, 16) = Cells(i, 35)
Lsb1.AddItem
Lsb1.List(i - 1, 17) = Cells(i, 36)
Lsb1.AddItem
Lsb1.List(i - 1, 18) = Cells(i, 37)
Lsb1.AddItem
Lsb1.List(i - 1, 19) = Cells(i, 38)
Lsb1.AddItem
Lsb1.List(i - 1, 20) = Cells(i, 39)
Lsb1.AddItem
Lsb1.List(i - 1, 21) = Cells(i, 40)
Next i
End Sub
Thanks in advance!
I am working on a program which is supposed to put columns S to AO in a listbox. I get a error message when I try to add more than 10 colomns. Does anybody know how i can fix this?
Also my scroller for my listbox is way bigger than needed. it goes far beyond my last filled in row.
Also i would like my top row to be visivle at all times when scrolling trough the listbox since it defines the rows. Anybody got something for these things too?
~Couple of things that you might want to know~
-All the colomns are equally long
- The length of colomn S is calculated with the code:
lenght_columns = Range("S2").End(xlDown).Row
-lsb1 = listbox1
This is my code:
Private Sub CommandButton1_Click()
lenght_columns = Range("S2").End(xlDown).Row
For i = 1 To lenght_columns
Lsb1.ColumnCount = 22
Lsb1.AddItem
Lsb1.List(i - 1, 0) = Cells(i, 19)
Lsb1.AddItem
Lsb1.List(i - 1, 1) = Cells(i, 20)
Lsb1.AddItem
Lsb1.List(i - 1, 2) = Cells(i, 21)
Lsb1.AddItem
Lsb1.List(i - 1, 3) = Cells(i, 22)
Lsb1.AddItem
Lsb1.List(i - 1, 4) = Cells(i, 23)
Lsb1.AddItem
Lsb1.List(i - 1, 5) = Cells(i, 24)
Lsb1.AddItem
Lsb1.List(i - 1, 6) = Cells(i, 25)
Lsb1.AddItem
Lsb1.List(i - 1, 7) = Cells(i, 26)
Lsb1.AddItem
Lsb1.List(i - 1, 8) = Cells(i, 27)
Lsb1.AddItem
Lsb1.List(i - 1, 9) = Cells(i, 28)
Lsb1.AddItem
Lsb1.List(i - 1, 10) = Cells(i, 29)
Lsb1.AddItem
Lsb1.List(i - 1, 11) = Cells(i, 30)
Lsb1.AddItem
Lsb1.List(i - 1, 12) = Cells(i, 31)
Lsb1.AddItem
Lsb1.List(i - 1, 13) = Cells(i, 32)
Lsb1.AddItem
Lsb1.List(i - 1, 14) = Cells(i, 33)
Lsb1.AddItem
Lsb1.List(i - 1, 15) = Cells(i, 34)
Lsb1.AddItem
Lsb1.List(i - 1, 16) = Cells(i, 35)
Lsb1.AddItem
Lsb1.List(i - 1, 17) = Cells(i, 36)
Lsb1.AddItem
Lsb1.List(i - 1, 18) = Cells(i, 37)
Lsb1.AddItem
Lsb1.List(i - 1, 19) = Cells(i, 38)
Lsb1.AddItem
Lsb1.List(i - 1, 20) = Cells(i, 39)
Lsb1.AddItem
Lsb1.List(i - 1, 21) = Cells(i, 40)
Next i
End Sub
Thanks in advance!