[RESOLVED] help: retrive column names of a worksheet into a listbox
Hi there,
I would like to fill my listbox with all the column headers (excel).
I am wondering if any of these would work
1) Using a SQL statement to retrieve all the column headers into the listbox
2) loop to last cell within the first row (excel takes 1st row by default to be column names) and additem to listbox at each loop.. i'd use a range to specify the first row/cells... so that i can refer to the individual cells using an integer.
http://www.anthony-vba.kefra.com/vba/range-3.gif
my loop will just consist be restricted to x=x+1 till end of last filled cell.
Kindly advise which method is viable? Anyone has examples to share? Thank you very much@ :wave:
Re: help: retrive column names of a worksheet into a listbox
vb Code:
lastcol = range("iv1").end(xltoleft).column
for i = 1 to lastcol
list1.additem cells(1, i)
next
Re: help: retrive column names of a worksheet into a listbox
BINGO! thank you westconn1
Re: [RESOLVED] help: retrive column names of a worksheet into a listbox
how can i specify the workbook/worksheet which i would like to retrive the column_names from?
my selectino of workbook/worksheet will be from a listbox..
e.g > listbox 1 will show all the worksheets available
by clicking on all the respective worksheet.. another listbox wld return all the column names..
thank you! =)
Re: [RESOLVED] help: retrive column names of a worksheet into a listbox
vb Code:
lastcol = sheets(listbox1.text).range("iv1").end(xltoleft).column
for i = 1 to lastcol
list2.additem sheets(listbox1.text).cells(1, i)
next
you will need to change list2 to the name of the listbox you want to fill
put the code in the click event of listbox1