PDA

View Full Version : Export listbox items to worksheet horizontally



heldenbreda
10-07-2015, 03:28 AM
Hello everyone,

I’m trying to export items from a listbox to a worksheet.
The code I’m using gives me the items in a vertically order, but I need the items in a horizontally order starting at the 3e column at the first row.
I have tried the following code:

Dim TheArray As Variant
Dim TheRange As Range
TheArray = ListBox2.List
Set TheRange = Blad10.Range(Blad10.Cells(1, 3), Blad10.Cells(1, 3 + UBound(TheArray))
TheRange = TheArray
End Sub

Thank you in advance!

Johann
10-07-2015, 10:32 PM
I tried to duplicate your code, but I do not have the *.List option available for a listbox!? There is ListIndex.

My thought was to use a for each loop with a counter moving the column to the right with each list item. Not sure if that's possible with a listbox.

Alternatively, I would consider using Listbox??.RowSource

heldenbreda
10-07-2015, 11:56 PM
Hello Johann,


Thank you for the response!
I fixed the problem using "Application.transpose" function, it works fine now.