Populating Userform ComboBox with worksheet names in XL2003

G

Guest

I'm trying to populate a ComboBox located in a userform with all of the
worksheet names in the workbook. I'm having problems getting this to work.
I found the following code in an earlier post, but no success:

for each sh in activeworkbook.sheets
combobox1.additem sh.name
next

How do I do this and where should the lines of code be located in the
overall code? What kind of sub procedure is this in (if any)?

Thanks for your help! (I'm very new to VBA and am learning as I go...)

-Mark
 
T

Tom Ogilvy

in the userform module, in the upper left dropdown select Userform and in
the Upper right dropdown select Initialize

Private Sub Userform_Initialize()

End Sub

will appear in the module. Put the code there

Private Sub Userform_Initialize()
Dim sh as worksheet
for each sh in activeworkbook.worksheets
me.combobox1.additem sh.name
next
End Sub

This event will fire whenever the userform is created.
 

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