Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel Hyperlink - jump to cell and scroll window

I am working in excel and I want to make a Hyper Link from the top of the page to another location on the page.

I type in a box at the top, and then right link and go down to hyper link in the dropdown menu I click it and select the tab that says "In This Work Book" and change it to where I want it to go. So all this is good and all but my Question is:

Can I make a Hyper link to bring me to a cell and scroll the window so the selected cell is the first row, instead of being near the bottom of the window?

Example:

Hyper link: "Test" Located in Cell A,1

Location Of Hyper Link: A,210

Now instead of having it put A,210 at the very Bottom and show the cells above it, I want to to be at the top and show the cells below it.

Thanks for the help,

like image 383
Dj Covey Avatar asked Dec 26 '22 19:12

Dj Covey


1 Answers

Add the following VBA code to your worksheet:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    ActiveWindow.ScrollRow = ActiveCell.Row
End Sub

By magic, when you click a link, that cell will be at the top. If you don't want this behavior for all links, you can test the Target address.

You will have to save the code as a xlsm file so that macros are enabled. Use Alt-F-11 to open the VBA editor so you can actually add the code (double click the worksheet in the left hand pane, then paste the above code in the window that opens).

like image 177
Floris Avatar answered Feb 23 '23 08:02

Floris