ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Automatically populate combo box. (https://www.excelbanter.com/excel-programming/359671-automatically-populate-combo-box.html)

[email protected]

Automatically populate combo box.
 
Hi All,

I have one combo box which contains the names of all the worksheets
within a workbook and one combo box which I would like to contain the
header row values for a particular worksheet which has been selected
from the first combo box.
I would like to know how I might go about making the second combo box
populate with the selected worksheet column header values just by
highlighting a particular worksheet in the first combo box and without
having to use a command button to complete the function.

i.e.

cboSelWksht
-------------------
worksheet1
worksheet2
worksheet3
-------------------

Highlight Worksheet1 populates combo box cboSelColumn with first values
for each column

cboSelColumn
--------------------
first Val A1
first Val B2
first Val C3
--------------------
etc.


Thanks very much for any help you provide.
--Brett--


K Dales[_2_]

Automatically populate combo box.
 
Use cboSelWksht's _Change procedure to set the values

Sub cboSelWksht_Change()
Dim ColHeader as Range
cboSelColumn.Clear
Set ColHeader = Worksheets(cboSelWksht.Value).Range("A1")
While ColHeader.Value < ""
cboSelColumn.AddItem ColHeader.Value
Set ColHeader = ColHeader.Offset(0,1)
Wend
End Sub
--
- K Dales


" wrote:

Hi All,

I have one combo box which contains the names of all the worksheets
within a workbook and one combo box which I would like to contain the
header row values for a particular worksheet which has been selected
from the first combo box.
I would like to know how I might go about making the second combo box
populate with the selected worksheet column header values just by
highlighting a particular worksheet in the first combo box and without
having to use a command button to complete the function.

i.e.

cboSelWksht
-------------------
worksheet1
worksheet2
worksheet3
-------------------

Highlight Worksheet1 populates combo box cboSelColumn with first values
for each column

cboSelColumn
--------------------
first Val A1
first Val B2
first Val C3
--------------------
etc.


Thanks very much for any help you provide.
--Brett--




All times are GMT +1. The time now is 11:16 AM.

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