ComboBox & ListBox - Add item but not first sheet

Lee Rabbit

New Member
Joined
Apr 30, 2020
Messages
43
Office Version
  1. 2010
Platform
  1. Windows
I am a bit stumped as I am still learning.

I have the following code in the first sheet of my workbook. The sheet is named "MASTER SHEET". I have populated both the ListBox & ComboBox with all sheets but I do not wish to have the "MASTER SHEET" displayed as a selectable option.

VBA Code:
Private Sub Worksheet_Activate()
    Dim sh As Worksheet
    
    
    Me.SelectDriver.Clear
    For Each sh In ThisWorkbook.Worksheets
    Me.SelectDriver.AddItem sh.NAME
    Next sh

    
    Me.ListBoxSh.Clear
    For Each sh In ThisWorkbook.Worksheets
    Me.ListBoxSh.AddItem sh.NAME
    Next sh

End Sub

I have tinkered as best I can before posting here as I really did want to resolve the issue myself but everything I have tried thus far has resulted in errors.

I am sure the answer is staring me in the face as I believe I will need something like this.....

VBA Code:
For i = 2 To Sheets.Count
If Sheets(i).Name Like "MASTER SHEET" Then

I guess it's the code placement that is baffling me.

A big thanks in advance to anyone who can steer me in the right direction.

Regards,
Lee
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
How about
VBA Code:
    For Each sh In ThisWorkbook.Worksheets
    If Not sh.Name = Me.Name Then Me.SelectDriver.AddItem sh.Name
    Next sh
 
Upvote 0
How about
VBA Code:
    For Each sh In ThisWorkbook.Worksheets
    If Not sh.Name = Me.Name Then Me.SelectDriver.AddItem sh.Name
    Next sh

Fluff, you are a legend! Thank you very much. I was tinkering with IF statements with no end product. This snippet of code will prove very useful to me in the future.

Regards,
Lee
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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