PDA

View Full Version : Listbox column Headings



tqm1
06-05-2007, 02:43 AM
Reference: 3 Hours before
http://www.excelforum.com/showthread.php?t=602393

Dear Experts

I use following codes to show data into a listbox.This work fine.
Now I want to show column heading as
column 1 heading=Date
column 2 heading=Sno
column 3 heading=Vehicle
column 4 heading=Weight
column 5 heading=Cash

Please help



Private Sub CommandButton1_Click()
Dim c As Range
Dim sDate As Date
Dim ws As Worksheet
Set ws = Worksheets("weight")
sDate = CDate(Me.TextBox1.Value)
ListBox1.Clear

For Each c In Worksheets("weight").Range("E:E")
If c.Value = sDate Then
With ListBox1
.ColumnCount = 5
.ColumnHeads = True
.ColumnWidths = "50;35;75;60;30"

.AddItem Format(ws.Cells(c.Row, "E").Value, "dd-mm-yy")
.List(.ListCount - 1, 1) = ws.Cells(c.Row, "B").Value
.List(.ListCount - 1, 2) = ws.Cells(c.Row, "D").Value
.List(.ListCount - 1, 3) = ws.Cells(c.Row, "N").Value
.List(.ListCount - 1, 4) = ws.Cells(c.Row, "M").Value
End With
End If
Next c
End Sub

Charlize
06-05-2007, 03:32 AM
You need to copy the values that match to a new sheet. Create a rowsource based on the copied values and then you can have columnheaders in a listbox (The columnlabels must equal the columnheaderstext that you want to appear at the listbox). Otherwise use a listview.

Charlize