Populate ComboBox with Worksheet Names

A

Allen

I'm trying to populate a combobox in a userform with the names of the
worksheets in my spreadsheet.

I'm guessing I'll just need to put it in a userform_initialize statement
with a For Each / Next loop, but am having trouble getting it to work.

Any syntax suggestions are much appreciated! Thanks
 
R

Rick Rothstein

Assuming your ComboBox is named ComboBox2, give this code a try...

Dim X As Long
....
....
For X = 1 To Worksheets.Count
ComboBox1.AddItem Worksheets(X).Name
Next
 
M

Mike H

Hi,

Try this

Private Sub UserForm_Initialize()
For x = 1 To Worksheets.Count
ComboBox1.AddItem Sheets(x).Name
Next
End Sub

Mike
 
A

Allen

That did the trick, thank you so much!


Mike H said:
Hi,

Try this

Private Sub UserForm_Initialize()
For x = 1 To Worksheets.Count
ComboBox1.AddItem Sheets(x).Name
Next
End Sub

Mike
 

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