ActiveX ComboBox to populate a specific worksheet names

Lology

New Member
Joined
Mar 13, 2018
Messages
6
Hi,

I have a workbook that contains of many worksheets, and I have been looking for an VBA code to get all these worksheets in a drop-down menu to make it easier in navigating between these worksheets and in order to save some time when searching for a specific data that is related to a different worksheets.

Luckily I found this VBA code:
Code:
Private Sub ComboBox1_DropButt*******()   
Dim xSheet As Worksheet
    On Error Resume Next
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    If ComboBox1.ListCount <> ThisWorkbook.Sheets.Count Then
        ComboBox1.Clear
        For Each xSheet In ThisWorkbook.Sheets
            ComboBox1.AddItem xSheet.Name
        Next xSheet
    End If
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
It works good for me, but i just wanna edit it to add a specific worksheets to the list and not all of them.

For example "I want it to add all worksheets that has "PAYROLL" in their names".

Any suggestions ?

Regards,
Mohamed El-Ghareeb
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Code:
For Each xSheet In ThisWorkbook.Sheets
    If Instr(xSheet.Name, "PAYROLL") > 0 Then ComboBox1.AddItem xSheet.Name
Next xSheet
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top