ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ListBox (https://www.excelbanter.com/excel-programming/273884-re-listbox.html)

Rob Bovey

ListBox
 
"Seth" wrote in message
...
I have a listbox control with columnheaders. How can I,
at run time, get the values of these headers (if
possible)?


Hi Seth,

The easiest way to do this is to read the RowSource property of the
ListBox, convert it into a Range object, then get the row directly above it,
which contains the headers. Here's an example of how this would work:

Private Sub CommandButton1_Click()
Dim rngCell As Range
Dim rngHeaders As Range
Set rngHeaders = Application.Range(ListBox1.RowSource) _
.Offset(-1, 0).Resize(1)
For Each rngCell In rngHeaders
MsgBox rngCell.Value
Next rngCell
End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *





All times are GMT +1. The time now is 02:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com