exclude sheet from list of combobox on userform

Abdo

Board Regular
Joined
May 16, 2022
Messages
183
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hello
I try excluding specific sheet from combobox on userform but still continue showing
so when populate sheets names in combobox1 should ignore sheets "Home" totally
VBA Code:
dim ws as worksheet
If ComboBox1.Value = "" Then Exit Sub
If ws.Name <> "Home" Then
Set ws = Sheets(ComboBox1.Value)
End If
ws.Activate
I hope some body guide me the right way
thanks
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
but you did not show me your script.
I think this error is not relating with active sheet , it doesn't show the form because the error . should fill the sheets names in combobox first .I use the code in UserForm_Initialize()

as to ComboBox1_Change() will select the sheet from combobox and will activate the sheet based on selected from combobox
 
Upvote 0
Now that I see the script and Combobox are being run on a user form try this:
VBA Code:
Private Sub CommandButton1_Click()
Dim i As Long
    With ComboBox1
        .Clear
        For i = 1 To Sheets.Count
            If Sheets(i).Name <> "Home" Then ComboBox1.AddItem Sheets(i).Name
        Next
    End With
End Sub
 
Upvote 0
Now that you say on initialize.
Try this:
It does not matter what the active sheet is:
VBA Code:
Private Sub UserForm_Initialize()
Dim i As Long
    With ComboBox1
        .Clear
        For i = 1 To Sheets.Count
            If Sheets(i).Name <> "Home" Then ComboBox1.AddItem Sheets(i).Name
        Next
    End With
End Sub
 
Upvote 1
Solution
You said this:
as to ComboBox1_Change() will select the sheet from combobox and will activate the sheet based on selected from combobox
Do you need help doing this also.

And why do you need to activate the sheet?
A lot of user's think to do anything to a sheet you need to activate it.
That is not true.
So, after you activate the sheet what do you want to do.
I'm not trying to be noisy but just wondering why you need to activate a sheet while using a Combobox.
See you could write a script which might say.
Sheets Combobox1.value.Range("A1").value="Alpha"
Never needing to activate the sheet.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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