Select Worksheets in Macro

tigerfan81

New Member
Joined
Apr 3, 2011
Messages
3
I'm looking for some code (user input box) to enable the user to select worksheets at a certain point in the macro. I have multiple workbooks and the sheets that need modification varies from workbook to workbook.

Thanks
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Code:
Sub Prompt_to_Select_Sheet()

    Dim strSheet As String, ws As Worksheet
    
Retry:
    strSheet = Application.InputBox("Enter the sheet name to select.", "Select Sheet", Type:=2)
    If strSheet = "False" Then Exit Sub     'User canceled
    
    On Error Resume Next
        Set ws = Sheets(strSheet)
    On Error GoTo 0
    
    If ws Is Nothing Then
        If MsgBox("Can't select the sheet named " & strSheet & vbCr & vbCr & _
                  "Try again?", vbExclamation + vbYesNo, "Sheet Not Found") _
                  = vbYes Then GoTo Retry
    Else
        ws.Select
    End If
    
End Sub
 
Upvote 0
Here's some code for an input box so you have only to enter a number.

Code:
Sub SheetSelection()
    Dim v(1 To 100) As Long
    Dim j As Long
    Dim i As Long
 
'Count the sheets
    WorkSheetList = ActiveWorkbook.Sheets.Count
 
'Create Sheetlist
 
    j = 0
    For i = 1 To WorkSheetList
    j = j + 1
    v(j) = i
    SheetList = SheetList & j & " - " & ActiveWorkbook.Sheets(i).Name & " " & vbCr
    Next i
 
'Show InputBox with list of sheets
   WorkSheetList = InputBox("Enter sheet number required." & vbCr & vbCr & SheetList)
 
'Sheet opens at  number input
   Sheets(v(WorkSheetList)).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,135
Members
452,890
Latest member
Nikhil Ramesh

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