Loading combo box list

G

Greg Snidow

Greetings. I am loading a combo box list on the initialize event with code I
found here, and it works perfectly.

For Each sh In ActiveWorkbook.Sheets
Me.ComboBox1.AddItem sh.Name
Next

However, there are two sheets, the last two that I don't want to show up in
the list. I can't find an easy way to keep these two sheets out. Any ideas?
Thank you.

Greg
 
G

Greg Snidow

Ok, that was easy.

For Each sh In ActiveWorkbook.Sheets
If sh.Name <> "BDMS" And sh.Name <> "HELD" Then
Me.ComboBox1.AddItem sh.Name
End If
Next
 
R

Ryan H

If it's always the last 2 sheets you don't want then you could use this which
would be a tade shorter. Hope this helps! If so, let me know, click "YES"
below.

For wks = 1 To Sheets.Count - 2
Me.ComboBox1.AddItem Sheets(wks).Name
Next wks
 
G

Greg Snidow

Thanks for the tip. That is actually what I was trying to do, but I was
making it much more complicated than you have done.
 

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