Page 1 of 1

VBA Listbox...need help filling ColumnHeads

Posted: Thu Feb 14, 2002 12:18 pm
by Packing Heat
Here's my code...
-------------------
'Variables declared in main module though
Public Cars As Object
Public Row As Integer
Set Cars = Sheets("Data").Cells
Public I as Integer

Private Sub UserForm_Initialize()

Row = 5
While Not IsEmpty(Cars(Row, 1))
ListCars.AddItem (Cars(Row, 1))
ListCars.Column(1, I) = (Cars(Row, 2))
ListCars.Column(2, I) = (Cars(Row, 3))
ListCars.Column(3, I) = (Cars(Row, 4))
ListCars.Column(4, I) = (Cars(Row, 5))
ListCars.Column(5, I) = (Cars(Row, 6))
ListCars.Column(6, I) = (Cars(Row, 7))
ListCars.Column(7, I) = (Cars(Row, 8))
ListCars.Column(8, I) = (Cars(Row, 9))
ListCars.Column(9, I) = (Cars(Row, 10))

I = I + 1
Row = Row + 1
Wend
End Sub
------------

Okay, ListCars is the listbox name. It has 10 columns. Cars refers to the sheet with the data on it. The data imported starts at row 5 in the worksheet. I want row 1 of the worksheet to be my columnheads.

How do I make that happen?

Posted: Thu Feb 14, 2002 12:34 pm
by Scott
Packing Heat,

I am learning VBA, John can answer better than I, but here goes.

Have you tried this:

ListCars.ColumnHeads = True 'Should display column heads

Note what VBA help says:

"Headings in combo boxes appear only when the list drops down.

Remarks

When the system uses the first row of data items as column headings, they can't be selected."

Never tried it, hope this helps


Scott

Posted: Thu Feb 14, 2002 1:16 pm
by Packing Heat
Thanks for attempting, but

ListCars.ColumnHeads = True just tells it that you want to display columnheads. The trouble I'm having is putting data in said columnheads. :P

Posted: Thu Feb 14, 2002 5:34 pm
by Scott
I believe in Excel you use:

ListCars.RowSource = "Cellrange"

Cellrange is the spreadsheet range where the data is coming from.

That's all I know

Posted: Fri Feb 15, 2002 8:05 am
by Packing Heat
Cheers Scott

I found that I had the button in the wrong sheet.

ListCars.RowSource = ("A2:J58")

That works.