![]() |
Populate ComboBox with Worksheet Names
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 |
Populate ComboBox with Worksheet Names
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 -- Rick (MVP - Excel) "Allen" wrote in message ... 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 |
Populate ComboBox with Worksheet Names
Hi,
Try this Private Sub UserForm_Initialize() For x = 1 To Worksheets.Count ComboBox1.AddItem Sheets(x).Name Next End Sub Mike "Allen" wrote: 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 |
Populate ComboBox with Worksheet Names
That did the trick, thank you so much!
"Mike H" wrote: Hi, Try this Private Sub UserForm_Initialize() For x = 1 To Worksheets.Count ComboBox1.AddItem Sheets(x).Name Next End Sub Mike "Allen" wrote: 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 |
Populate ComboBox with Worksheet Names
Your welcome and thanks for the feedback
"Allen" wrote: That did the trick, thank you so much! "Mike H" wrote: Hi, Try this Private Sub UserForm_Initialize() For x = 1 To Worksheets.Count ComboBox1.AddItem Sheets(x).Name Next End Sub Mike "Allen" wrote: 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 |
All times are GMT +1. The time now is 05:28 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com