Allow Users to select A Sheet

rwilfing

New Member
Joined
Jul 4, 2011
Messages
8
Is it possible to create a listbox that populates the name of all the sheets in a workbook and allow the user to activate that sheet to finish running the macro?

Thanks in Advance
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
If someone can tell me how to have a listbox without creating a userform... I think I can help.
 
Upvote 0
One workaround would be to use Application.InputBox with type:=8, to have the user navigate to that sheet normaly with the mouse.
 
Upvote 0
But can you have a listbox or combobox show up without making a userform?
a la msgbox or inputbox?
 
Upvote 0
You could use a CommandBarComboBox

Code:
Option Explicit
Const cbName As String = "myTemp"

Sub SelectASheet()
    Dim oneSheet As Worksheet
    
    On Error Resume Next
    Application.CommandBars(cbName).Delete
    On Error GoTo ErrorOut
    
    With Application.CommandBars.Add(Name:=cbName, Position:=msoBarFloating, temporary:=True)
        .Left = 300
        .Top = 200
        .Visible = True
        
        With .Controls.Add(Type:=msoControlDropdown, temporary:=True)
            .Width = 150
            .Height = 30
            .Visible = True
            
            For Each oneSheet In ThisWorkbook.Worksheets
                .AddItem oneSheet.Name
                If oneSheet.Name = ActiveSheet.Name Then
                    .ListIndex = .ListCount
                End If
            Next oneSheet
            
            .OnAction = "GoToSelectedSheet"
        End With
        
    End With
    
ErrorOut:
    On Error GoTo 0
End Sub

Sub GoToSelectedSheet(Optional dummy As Boolean)
    On Error Resume Next
    With Application.CommandBars(cbName)
    
        With .Controls(1)
            ThisWorkbook.Sheets(.List(.ListIndex)).Activate
        End With
        
        '.Visible = False: Rem optional line
        
    End With
    On Error GoTo 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

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