Add Listbox header using VBA

S

shirley_kee

I have Column A to BH in my excel sheet. I want to display column A, B
,C,E, G and BH in a userform listbox. I've manage to use VBA to add
selected column data into the listbox. My problem is I have no idea how
to create a list header on top of the list box. I try using the additem
but it doesn't work.

My listbox has horizontal scrollbar as the list is too long so I can't
use label to create the list header name

Please help...
 
B

Bob Phillips

AFAIK you can't, you can only get headers if you bind the listbox to a
range.

In the ListBox,
- set the ColumnCount property to number of columns,
- set ColumnHeads to True,
- set RowSource to the range of cells >>below<< the column headers text

The cells above this RowSource range will be used as column headers.

You can set the rowsource in VBA

With Me.ListBox1
.RowSource = Range("A2:A5").Address
End With


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"shirley_kee" <[email protected]>
wrote in message
news:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top