hyperlink open location

DH888

Board Regular
Joined
Jul 15, 2015
Messages
147
How can i get hyperlinks to locations within the same workbook to open with the linked cell at the top of the window instead of the bottom
Thanks
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
If your hyperlinks are located all within the same sheet, you can use the Worksheet_FollowHyperlink event. Right click the sheet tab for the sheet containing the hyperlinks, select View Code, and then copy/paste the following code into the code module for the sheet...

Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Worksheet_FollowHyperlink([COLOR=darkblue]ByVal[/COLOR] Target [COLOR=darkblue]As[/COLOR] Hyperlink)
    [COLOR=darkblue]Dim[/COLOR] strSheetName [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    [COLOR=darkblue]Dim[/COLOR] strRef [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    strSheetName = Replace(Split(Target.SubAddress, "!")(0), "'", "")
    strRef = Split(Target.SubAddress, "!")(1)
    Application.Goto Reference:=Sheets(strSheetName).Range(strRef), Scroll:=[COLOR=darkblue]True[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

If your hyperlinks are located throughout the workbook, you can use the Workbook_SheetFollowHyperlink event. In the Visual Basic Editor, and under the Project Explorer window, right-click ThisWorkbook for the workbook containing your hyperlinks, select View Code, and copy/paste the following code into the code module for the workbook...

Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Workbook_SheetFollowHyperlink([COLOR=darkblue]ByVal[/COLOR] Sh [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Object[/COLOR], [COLOR=darkblue]ByVal[/COLOR] Target [COLOR=darkblue]As[/COLOR] Hyperlink)
    [COLOR=darkblue]Dim[/COLOR] strSheetName [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    [COLOR=darkblue]Dim[/COLOR] strRef [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    strSheetName = Replace(Split(Target.SubAddress, "!")(0), "'", "")
    strRef = Split(Target.SubAddress, "!")(1)
    Application.Goto Reference:=Sheets(strSheetName).Range(strRef), Scroll:=[COLOR=darkblue]True[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Hope this helps!
 
Upvote 0
The hyperlinks are all in an index tab they point to other sheets within the same workbook.

Is that what you mean by this
If your hyperlinks are located throughout the workbook

It's unclear to me if you mean the actual hyperlinked cells or the destinations the linked cells actually send you to.

Thanks for the solution I'll try it once I know what you meant by this statement.
 
Last edited:
Upvote 0
I meant the actual hyperlinked cells (the cells containing the hyperlinks). So since you say that the hyperlinks are all in an index tab, use the first one, the Worksheet_FollowHyperlink event.
 
Upvote 0
Does this help?

Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Worksheet_FollowHyperlink([COLOR=darkblue]ByVal[/COLOR] Target [COLOR=darkblue]As[/COLOR] Hyperlink)

    [COLOR=darkblue]Dim[/COLOR] strSheetName [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    [COLOR=darkblue]Dim[/COLOR] strRef [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    
    strSheetName = Split(Target.SubAddress, "!")(0)
    [COLOR=darkblue]If[/COLOR] Left(strSheetName, 1) = "'" And Right(strSheetName, 1) = "'" Then
        strSheetName = Mid(strSheetName, 2, Len(strSheetName) - 2)
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    strSheetName = Replace(strSheetName, "''", "'")
    
    strRef = Split(Target.SubAddress, "!")(1)
    
    Application.Goto Reference:=Sheets(strSheetName).Range(strRef), Scroll:=[COLOR=darkblue]True[/COLOR]
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,215,334
Messages
6,124,323
Members
449,154
Latest member
pollardxlsm

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