If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
automatic sheet selection
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 |
#2
|
|||
|
|||
automatic sheet selection
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 "swiftcode" wrote: 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 |
#3
|
|||
|
|||
automatic sheet selection
Hi Jackpot,
Thank you, your macro is exactly what i was looking for. Rgds Ray "Jackpot" wrote: 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 "swiftcode" wrote: 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 |
Thread Tools | |
Display Modes | |
|
|