automatic sheet selection

  • Thread starter Thread starter swiftcode
  • Start date Start date
S

swiftcode

Hi all,

I need some help on the following. Assuming on sheet 1 in a workbook, in
column A2 to A30, i have the sheet names listed in each cell, how am i able
to write a macro when i selection the cell directly next to it eg B2, to
automatically jump to and select sheet 2 in my workbook.

Thank you in advance for any help rendered.

Rgds
Ray
 
Either use a formula in B2 to B30

=HYPERLINK("#"&CELL("address",INDIRECT(A2 & "!A1")),"Goto")

OR if you have data in colB; try the below worksheet event..Select the sheet
tab which you want to work with. Right click the sheet tab and click on 'View
Code'. This will launch VBE. Paste the below code to the right blank portion.
Get back to workbook and try out.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
If Not Application.Intersect(Target, Range("B2:B30")) Is Nothing Then
If SheetExists(CStr(Target.Offset(, -1))) Then
Application.EnableEvents = False
Sheets(CStr(Target.Offset(, -1))).Activate
Application.EnableEvents = True
End If
End If
End If
End Sub

Function SheetExists(strSheet As String) As Boolean
Dim ws As Worksheet
On Error Resume Next
Set ws = Sheets(strSheet)
If Not ws Is Nothing Then SheetExists = True
End Function
 
Back
Top