Drop down menu needs work

RLPeloquin

Board Regular
Joined
Jul 4, 2020
Messages
73
Office Version
  1. 2019
Platform
  1. Windows
The code works fine but when I select "Site1" for example then return to "Home" the drop down stays open. I'd like for it to show "Home" once returning to "Home". Maybe this picture will help

Private Sub ComboBox1_Change()
'Updateby Extendoffice
If ComboBox1.ListIndex > -1 Then Sheets(ComboBox1.Text).Select
End Sub
Private Sub ComboBox1_DropButtonClick()
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
Private Sub ComboBox1_GotFocus()
If ComboBox1.ListCount <> 0 Then ComboBox1.DropDown
End Sub
 

Attachments

  • Sample2.png
    Sample2.png
    7 KB · Views: 13
  • Sample.png
    Sample.png
    17.5 KB · Views: 13

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I assume what your wanting is when you select a value in the Combobox you then want the Combobox to show nothing in the Combobox selection Box
If so use a script like this:
VBA Code:
Private Sub ComboBox1_Click()
'Modified  5/5/2021  12:40:58 PM  EDT
Range("G1").Value = ComboBox1.Value
ComboBox1.ListIndex = -1
End Sub
 
Upvote 0
I assume what your wanting is when you select a value in the Combobox you then want the Combobox to show nothing in the Combobox selection Box
If so use a script like this:
VBA Code:
Private Sub ComboBox1_Click()
'Modified  5/5/2021  12:40:58 PM  EDT
Range("G1").Value = ComboBox1.Value
ComboBox1.ListIndex = -1
End Sub
I've fixed part of the original post. The only problem I'm having now is to show "Select Site Number" in the Combobox once "Home" Tab is selected and not any Sites
 
Last edited:
Upvote 0
Is this approximately what you are looking for? Or is something like this too complicated?
 

Attachments

  • 210505 1.jpg
    210505 1.jpg
    14.2 KB · Views: 9
Upvote 0
Is this approximately what you are looking for? Or is something like this too complicated?
This is my corrected Code: This works for me. Thanks for your help
Private Sub ComboBox1_Change()
If ComboBox1.ListIndex > -1 Then Sheets(ComboBox1.Text).Select
'ComboBox1.ListIndex = -1 'Added This Line
End Sub
Private Sub ComboBox1_DropButtonClick()
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
'Deleted this Sub :
Private Sub ComboBox1_GotFocus()
If ComboBox1.ListCount <> 0 Then ComboBox1.DropDown
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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