In Excel 2010, I can create an ActiveX ComboBox in a worksheet and configure it to give me a list of all worksheets, and it will activate whichever worksheet I select.
However, if I copy the worksheet containing the ComboBox, the new ComboBox is dead. I have to duplicate all the VBA code that makes it work, changing the labels accordingly.
Is there any way to set it up so that it works automatically if I copy the worksheet?
This is how I'm currently doing it:
Microsoft Excel Objects \ ThisWorkbook:
Private Sub Workbook_Open()
' Rebuild the list of sheets for the worksheet ComboBox.
Dim i As Long
For i = 1 To ThisWorkbook.Sheets.Count
Sheet1.ComboBox1.AddItem Sheets(i).Name
Next
End Sub
Microsoft Excel Objects \ Sheet1(Sheet1):
Private Sub ComboBox1_Change()
With Sheet1.ComboBox1
Sheets(.List(.ListIndex)).Activate
End With
End Sub
Sheet1
make it sayMe
, and I think then the code should be portable between sheets. If the copied sheets do not preserve the ComboBox name, then just rename the ComboBox instead of revising each CB's event procedure. – David ZemenscbSheet
in my case). 3) tested your code, but replacedSheet1
with Me and 4) Copy the sheet I had the combobox on and it tested the code again, which worked perfectly without having to make any adjustments. – Scott Holtzman