Forum

jump to specific sh...
 
Notifications
Clear all

jump to specific sheet

5 Posts
3 Users
0 Reactions
327 Views
(@rathanak)
Posts: 55
Trusted Member
Topic starter
 

Dear Expert,

I write a code below to jump to specific sheet.

Sub test()

Dim i As integer

i = applcation.inputBox("Enter worksheet number", "sheet selection",type=:1)

MsgBox "Sheet " & i & "selected!"

Sheets("Sheet" & i).Select

End sub

Please kindly comments if any moderate or new method

 

Regards,

 
Posted : 11/09/2016 10:26 pm
(@sunnykow)
Posts: 1417
Noble Member
 

Hi rathanak

Your code will cause an error if user press ESC/Cancel or enter a non-existence sheet number.

I have modified your code so give it a try. It will allow you to select by the worksheet's name instead of number.

Sub SelectSheet()
Dim i As Variant
Dim ws As Worksheet
i = Application.InputBox("Enter worksheet name", "Select sheet")

'Cancel was pressed
If i = False Or Trim(i) = "" Then Exit Sub

'Check if sheet exist
On Error Resume Next
Set ws = Sheets(i)
On Error GoTo 0

If ws Is Nothing Then
MsgBox "Worksheet " & i & " not found!"
Else
Sheets(i).Select
MsgBox "Worksheet " & Sheets(i).Name & " selected!"
End If
End Sub

 
Posted : 12/09/2016 2:01 am
(@rathanak)
Posts: 55
Trusted Member
Topic starter
 

Thanks Suuny,you're so awesome

 
Posted : 12/09/2016 4:10 am
(@david_ng)
Posts: 310
Reputable Member
 

Thanks Sunny you are beautiful to create this Select Sheets Macro

As too  many sheets in a wrokbook sometimes make us  confuse and easily get lost or how to be the desired Sheet  effectively.

I write a little bit macro too to list all sheet then using your Selected Sheet Macro , now make life a lot easier.

 

Now can go home earlier have some sleep..

 
Posted : 16/12/2016 3:41 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi David

Happy to know you find the macro useful and have modified it to list all worksheets in the workbook for easier selection.

Enjoy your sleep....Z Z Z Z Z Z Z Z Z Z

Sunny

 
Posted : 16/12/2016 4:57 am
Share: