SYSTEM NOTICE

Auto translation by AI. Be sure, accuracy, nuances and authorial intent may not be fully reflected.
見出し画像

Google Sheets: How to create hyperlinks to specific cells

This is the second installment of a note delving into Google Sheets' hyperlink feature, and the HYPERLINK function.

Last time, I wrote about hyperlinks to so-called websites.

There were some frustrating aspects compared to Excel, such as not being able to add hyperlinks to shapes or images on cells, but there were also many convenient features unique to Google Sheets, such as the "simplest" way to generate hyperlinks, bulk hyperlinking of URLs using "Find and Replace", and the link preview feature. I think it was an episode where we discovered, "This is useful!" right?

If you have something you want to do related to hyperlinks and want to know how to do it, it might be a good idea to look from the summary at the end of the previous article.




Understanding links within spreadsheets

This time, I will write about hyperlinks that allow you to jump to other sheets or specific cells within a spreadsheet file, so-called within the workbook.

First, let's understand how to create a link to a specific cell using the basic "Insert link" feature, and the behavior of hyperlinks within a sheet.



Using Insert link to specify a sheet or specific cell for a link

The "Insert link" feature, which I introduced last time as a way to generate hyperlinks to open websites, can also be used when creating hyperlinks within a spreadsheet.

For this, select the cell where you want to create the hyperlink, i.e., not the jump destination but the jump source cell,

  • Select the link icon (which looks like a paperclip) on the menu bar

  • Select Insert > Link from the menu

  • Right-click the cell and select Insert link

  • Use the shortcut Ctrl + K

You can use any of these methods in the same way. (They are all the same.)

Since a display like the image above will appear, enter the text to be displayed in the cell (link label) in "Text", and this time, without using the search box below it, click "Sheets and named ranges" at the bottom.

If text has already been entered in the cell, the string within the cell will be automatically entered into this "Text" field.

↑ It will look like this screen, so from here, select the sheet or named range you want to jump to.

If you want to specify a particular cell as the jump destination, click Select a range of cells to add a link at the bottom.

You can create a hyperlink that jumps to a specific cell by selecting it with a click like this, or by entering it directly.

Let's test the hyperlink you created.

Jumping to a specified cell within the same sheet

Of course, it is also possible to specify a specific cell on a different sheet and jump across sheets.

In the case of a specified cell on a different sheet

By the way, the moment the destination cell becomes selected (active) after jumping (though there is a slight time lag), I have it highlight the cell to make it easier to see.

If you are interested in this, please refer to my past note where I wrote about how to highlight cells using GAS.

Even when jumping via a hyperlink, the simple trigger onSelectionChange(e) works.



You can preview the text of the linked cell

As I wrote last time, hyperlinks in Google Sheets are convenient because for websites, you can preview the top image or site title.

This is also effective for hyperlinks to specific cells, and it is convenient because you can preview the text inside the destination cell.

Of course, if the text in the linked cell is changed, it will be reflected immediately.

Unfortunately, you cannot preview images even if there is an image inside the cell at the link destination. Only text can be previewed with hyperlinks to cells.



You can also specify a cell range as the link destination

Up to this point, I have specified a single cell as the link destination, but it is also possible to set the link destination to a cell range.

If you specify a cell range (for example, E11:I20 on Sheet1) from Select a range of cells to add a link in the Insert link menu mentioned earlier,

when you jump via a hyperlink like this, the specified cell range becomes selected (active), allowing you to copy them all at once (Ctrl + C) or paste cells you had previously copied (Ctrl + V).



If you want to start typing immediately in the cell you jumped to, you need to press Esc once.

There are many cases where you want to edit (type in) a cell immediately after jumping to it via a hyperlink. However, for some reason, you cannot type directly.

You also cannot move to adjacent cells using the arrow keys.

It won't move.

Of course, you can edit or operate it if you click the cell again with the mouse, but if possible, I would like to handle it using only the keyboard.

There is a workaround for this.

By pressing the Esc key once, you will be able to type in the destination cell.

It is probably because the focused layer is different, but for now, let's put the reason aside and just assume that is how it is designed.



Keyboard shortcuts cannot "basically" jump to a specific cell

I was able to handle the operation of the linked (destination) cell using only the keyboard.

Now, conversely, is it possible to jump to a hyperlinked cell without clicking with the mouse from the source cell?

Google Sheets does not have a "good way" to jump to a specific cell via hyperlink using the keyboard. (Probably)

Previously, I introduced a way to open multiple hyperlinks at once by right-clicking and selecting Show other cell actions > Open link. It seems like the shortcut key Alt + Enter could be used, but

As you can see, even if it is within the same sheet, if you open a link with Alt + Enter, it will open another instance of the same spreadsheet in a separate tab instead of jumping.

Conversely, since clicking with a mouse jumps to the specific cell hyperlink, you can utilize this Alt + Enter if you want to open another instance separately.

So, the reason I wrote that there is no "good way" is not because it is "impossible".

There is a way!! (Though it is not recommended)

Did you understand?

With the hyperlink cell selected, first use the shortcut

Ctrl+Alt+Shift+M to move focus out of the spreadsheet

to use this shortcut.

By doing this, you can navigate with Tab on the layer above, so you can reach Select Hyperlink via the top menu and press Enter.

By the way, while I am operating slowly above for clarity, you don't need to press Tab many times; at the end of the Tab navigation, it just loops through the selected cell's hyperlink menu, so you can just hold down Tab lol

With this method, you can edit the linked cell immediately without pressing Esc.

It is a hack that allows you to operate using only the keyboard without a mouse, but it feels a bit forced, so it's not great as a keyboard shortcut.

Personally, I don't recommend it... (I know it, but I don't use it myself).

[Updated September 2025] Due to specification changes, the method above for jumping to other cells via hyperlink using only the keyboard is no longer available.


This covers the basics of using "Insert link" to create hyperlinks that jump to specific cells or sheets within a spreadsheet.



Understanding URLs for links within a sheet

So, what should you do if you don't want a link that jumps to a specific cell within the same spreadsheet, but instead want someone to open a specific cell in a spreadsheet directly from a link pasted into another spreadsheet (a different workbook), a Google Doc, or sent via chat or email?

To do this, you need to understand the structure of Google Sheets URLs.



How to use "Get link to this cell"

When you want someone to look at a specific part of a spreadsheet or have it jump there when opened, you can use the "Get link to this cell" feature.

From a right-click, select View more cell actions > Get link to this cell

When you select this, the link will be copied to your clipboard.

The link URL you can obtain here is

https://docs.google.com/spreadsheets/d/ spreadsheet ID /edit#gid= sheet ID &range=cell position in A1 notation

It looks something like this.

You can specify the sheet with this sheet ID, and the cell with the cell position in A1 notation.

If you paste this as-is into an appropriate cell in the sheet,

it becomes a link that jumps to the specified cell within the spreadsheet like this.

Of course, if you paste this URL into a Google Doc or email, or register it as a bookmark, the moment you open the link,

it will open the spreadsheet with the specified cell focused, like this.

It is a quite useful feature because you can directly open the place you want someone to look at or work on without having to explain the cell position by saying, "It's written in the cell at column E, row 23 of the sheet called XX."

If you understand the spreadsheet ID, sheet ID, and cell position URL structure for links that open a specific cell in a directly specified sheet,

for example, you can copy the URL of the opened sheet and, by adding

&range=cell position (A1 notation)

to the end, you can easily create a direct link to a specific cell manually.



Cell-specifying URLs can only be converted into chips at the moment they are pasted into a cell.

A key feature of Google Workspace is the ability to search for and embed files within Google Drive as smart chips using the half-width @ symbol.

Actually, the cell-specifying URL obtained via "Get link to this cell" can also be turned into a smart chip.

However, this cell-specifying URL can only be turned into a smart chip temporarily, before you press Enter to confirm after pasting the URL into the cell.

Normally, for other spreadsheet URLs, as I wrote in my previous note, they are treated the same as external websites; as shown on the right in the image, the site's (spreadsheet's) title and a preview are displayed, and an option to convert to chip? is displayed at the bottom.

However, in the case of a URL to a specific cell within the same spreadsheet, as shown on the left in the image, it becomes an in-sheet link display where the text of the destination cell is previewed, just like the one created with "Insert link" earlier, and it cannot be turned into a chip afterwards.

This is likely because when a link URL to a specific cell within the same spreadsheet is finalized in a cell, the link URL is converted to a simplified form (only #gid=...) as shown above.

In other words, for links within the same spreadsheet,

https://docs.google.com/spreadsheets/d/ spreadsheet ID /edit#gid= sheet ID &range=cell position in A1 notation


#gid= sheet ID &range=cell position in A1 notation

This means you can specify it using a simplified form of the sheet ID and cell information like this.



Generating a link to a specific cell in a sheet using the HYPERLINK function

#gid= sheet ID &range=cell position in A1 notation

Utilizing this simplified notation for links to specific cells, let's try generating a link that jumps to a specific cell using the HYPERLINK function instead of the feature.

While it is easier to create a link to a specified cell using the "Insert link" feature introduced earlier, using the HYPERLINK function allows you to create links to specific cells with greater flexibility.



Generating a link to a specific cell with the HYPERLINK function

When using the HYPERLINK function

=HYPERLINK("#gid= sheet ID &range=cell position in A1 notation","[link label]")

※ & can be omitted

Create it like this. The sheet ID can be obtained from the URL while the relevant sheet in the spreadsheet is open. (the consecutive numbers after #gid=, or 0)

If you want to jump to cell E8, set range=E8.

=HYPERLINK("#gid=682523035&range=E8","Jump")

Reference

A hyperlink to a specific cell created with the HYPERLINK function behaves the same way as one created with the feature.

The key point is the sheet ID.

In the case of Google Sheets, you need the sheet ID even when jumping to a specific cell within the same sheet.

Furthermore, unfortunately, there is basically no way to obtain the sheet ID other than checking the URL and copying and pasting it.

For reference, regarding sheet IDs:

■ Rules for Google Sheets sheet IDs
・Sheet1 of a newly created spreadsheet has gid=0
・Sheets added after that have a random number of about 8 to 10 digits
・If a spreadsheet is copied, the sheet IDs are carried over
・If a sheet is copied to another spreadsheet, the sheet ID changes

While there are such rules, there is no way provided to obtain the sheet ID through features or standard sheet functions.

By the way, "sheets added after that" applies not only to new creations but also when created by copying a sheet.

In other words, if you copy a sheet that has a link set to a specific cell within the sheet (for example, E8), the hyperlink to the specific cell in the sheet generated by the copy (a copy of Sheet1) will not jump to E8 of the copy of Sheet1, but rather will jump to E8 of the original sheet (Sheet1).

Unfortunately, for links to specific cells, both the HYPERLINK function and the insert link feature have sheet information tied to them, so the link destination does not change relatively.

The only exception is when you copy the spreadsheet (file), in which case the sheet IDs are carried over, so the hyperlinks within the spreadsheet can be used as they are in the copied spreadsheet.



In Excel, you can easily specify a link to a specific cell with #

Hyperlinks to specific cells within the same file (workbook) are overwhelmingly easier on the Excel side.

For a hyperlink to a specific cell (e.g., E8) within the same sheet, including the web version:

=HYPERLINK("#E8","Jump")

For a hyperlink to a specific cell (E8) on a different sheet (e.g., Sheet2):

=HYPERLINK("#Sheet2!E8","Jump")

Like this, by adding # to the beginning of the string indicating the sheet or position, you can specify it as the link destination.

If it was a link to a cell within the same sheet, even if you copy the cell containing the HYPERLINK function to another sheet, it will function as is within the destination sheet.

When copied to Sheet2, it becomes a link that jumps to E8 of Sheet2

I feel that links to specific cells within a sheet or workbook are easier to create in Excel.



With the installed version of Excel, you can jump to a specific cell via a hyperlink and then return.

By the way, while this is not possible in the web version, in the installed version of Excel, after moving to a specific cell via a hyperlink, you can return to the original hyperlink cell using "Go To" function.

The "Go To" feature is one of Excel's excellent features that Google Sheets lacks, but it can be used to return from a hyperlink destination.

Since it is a frequently used feature, it might be good to remember it with the keyboard shortcut Ctrl + G.

The web version of Excel also has a Go To feature, but it seems it does not remember the previously selected cell, so this method does not work.


In the case of Google Sheets, there is no Go To feature to begin with (pressing Ctrl + G displays the same simple search as Ctrl + F), and even when clicking a hyperlink, the cell containing the hyperlink does not become selected.

Even if you want to do it just like in Excel!, unfortunately, it is considered difficult.



Use GAS custom functions (user-defined functions) to get the sheet ID

So, in Google Sheets where the sheet ID is always required, is there no way to easily and generically create hyperlinks to specific cells using the HYPERLINK function?

I wrote that you basically have to get the sheet ID manually, but actually, this can be solved by using GAS.

And by creating a custom function (user-defined function) that automatically retrieves the sheet ID using GAS and combining it with the HYPERLINK function, you can easily create generic hyperlinks to specific cells within the sheet.

If the sheet ID of the sheet containing the formula can be retrieved automatically, even if you copy cells or sheets, it becomes a hyperlink that always jumps to a specific cell in the same sheet with relative reference behavior!

The code is simple, and since it is a custom function, script authorization is not required, so I recommend solving this using GAS.

↑ I have introduced this on note in the past, but I will touch on it briefly here.

For example, if you just want to get the sheet ID of the sheet where the custom function is inserted (active sheet)

function sheetId(){
  return SpreadsheetApp.getActiveSheet().getSheetId();
}

this one-line code is enough. Just add an = to the beginning of this function name sheetId()

=sheetId() and enter that function into a cell.

In this way, you have obtained the sheet ID.

Combine this with the HYPERLINK function

=HYPERLINK("#gid="&sheetId()&"&range=E8","Jump")

If you build and use a formula like this, no matter which sheet you put it in, a versatile hyperlink to a specific cell that jumps to cell E8 of the sheet where the formula is placed is complete.

Since this is difficult with the Insert Link feature, this can be said to be a merit of using the HYPERLINK function.


It worked properly even when copied to another location.

In a past note, I also introduced how to create a linked index of all sheets (table of contents) that applies this further.



Generate the A1 notation of the cell position with a formula to make the jump destination variable

=HYPERLINK("#gid= Sheet ID &range=A1 notation of cell position","[Link Label]")

Another merit of generating a link to a specific cell with the HYPERLINK function is that the cell position can also be generated and made variable using a formula.

This also overlaps with a topic I wrote about in a past note, but for example, if there is a list of dates in column A, if you want to jump to today (or the most recent date), it is easier and has advantages to jump using the HYPERLINK function rather than using GAS.



Applied problems for the HYPERLINK function to a specific cell within a sheet

Since we are at it, let's try the arrangement problem of the date jump formula using XMATCH and HYPERLINK that I wrote about before.

There are two problems: a relatively easy one and a moderately difficult applied one.



Q1. When the link is clicked, I want to jump to today's date among the dates lined up horizontally.

Suppose there is a shift schedule like the image above with dates lined up horizontally in the second row. I want to set a hyperlink in this A1 cell that jumps to the cell with today's date in the second row.

What kind of formula should I use inside the HYPERLINK function?

It's not vertical, but jumping horizontally. Let's think about it!








↓↓↓ Answer





A1. A formula that jumps to today's date among dates arranged horizontally when the link is clicked

Here is the answer.

Ta-da!

=HYPERLINK("#gid=SheetID&range="&
ADDRESS(2,MATCH(TODAY(),2:2,0),4),"Jump to today's column")

or

=HYPERLINK("#gid=SheetID&range="&
ADDRESS(2,XMATCH(TODAY(),2:2),4),"Jump to today's column")

It's relatively simple.

MATCH function, or XMATCH function is used to search for the position of 2:2 (the entire second row) for TODAY(), which is today's date.

Since it's Google Sheets, I'd like to actively use XMATCH, but since there are many cases where it can be handled with MATCH, the frequency of use doesn't really go up.

In the case of MATCH, just like VLOOKUP, the default setting is not an exact match search but an approximate match search, so you must specify an exact match search by setting the third argument to FALSE (or 0).

On the other hand, XMATCH, like XLOOKUP, has a default setting of an exact match search.

The result returned is the position where the search hit (the Nth item) within the range, and since this becomes the column number, we pass this along with the row number 2 to the ADDRESS function to obtain the cell address string in A1 notation.

ADDRESS(row, column, [absolute_relative_mode], [use_A1_notation], [sheet])

What is important here is the third argument, absolute_relative_mode, of the ADDRESS function, and by setting this to 4, we obtain A1 notation without $.

E8 is fine, but $E$8 will not work.

This is because a link to a specific cell does not function if there is a $ attached to the A1 notation.

Are you starting to get a feel for how to use HYPERLINK in combination with other functions?

Let's try one more topic, this time with a higher difficulty level.



Q2. I want to output a list of links for cells containing keywords within a range using a formula.

This is an application example of the HYPERLINK function.

For example, as shown in the image above, I want to search for cells containing the keyword entered in cell A2 from the data range C3:I, and display the hit search cells in a list starting from A5, in a state where they are hyperlinks that jump to that cell when clicked.

Is something like this possible?

For now, the start is

=ARRAYFORMULA(LET(key,A2,data,C3:I,

I am doing it this way, but it is okay to think of a different method.

It is a bit difficult, but if you are confident, let's give it a try!








↓↓↓Answer





A2. Output a list of links for cells containing keywords within a range using a formula

Here is the answer. (This is just one example of an answer. There may be other methods.)

=ARRAYFORMULA(LET(
key,A2,data,C3:I,
TOCOL(IF(REGEXMATCH(data,key),
HYPERLINK("#gid=SheetID&range="&
ADDRESS(ROW(data),COLUMN(data),4),data),),3)))

It might be better to use the following if you want to account for when A2 is empty.

=ARRAYFORMULA(LET(
key,A2,data,C3:I,
IF(key="",,TOCOL(IF(REGEXMATCH(data,key),
HYPERLINK("#gid=345754649&range="&
ADDRESS(ROW(data),COLUMN(data),4),data),),3))))

Since this is not a search for a specific column or row, I am using ARRAYFORMULA to process all cells, and using an IF function to return a hyperlink if it contains the keyword, or an empty cell if it does not. (Therefore, this is a somewhat heavy process.)

I am using REGEXMATCH for "contains," but FIND is also fine here.

For generating the hyperlink, I am using ADDRESS just like before.

HYPERLINK("#gid=SheetID&range="&
ADDRESS(ROW(data),COLUMN(data),4),data)

Finally, I use TOCOL to exclude empty cells and pack the results upward into column A.

It wouldn't be too redundant even if written as is, but I have used the LET function to assign variables just in case.

If the amount of data is large, processing may take quite a while.

If the data volume is large and processing is too heavy, it might be better to use Find and Replace or GAS TextFinder.

That was an application example of the HYPERLINK function.

I have also introduced a similar example of using the SORT function combined with the HYPERLINK function in the past.



How to create hyperlinks that can relatively adapt even if rows or columns are added

If you understand the application of the HYPERLINK function and how to combine it with the ADDRESS function, you can create links that can relatively follow even if rows or columns are added.

What does it mean to have a hyperlink that can follow relatively?

Even if you set it up so that you can jump to the "Here it is!" cell (E8 at this point) using the HYPERLINK function like this, if rows or columns are added or deleted afterward and the "Here it is!" cell moves to F9, the cell the link jumps to will remain E8.

There are cases where you want to make this relatively referenced so that it links to "Here it is!" even if rows or columns are added or deleted.



Following the link destination with the HYPERLINK and ADDRESS functions

This can be handled by arranging the "E8" string within the link address into a formula that generates the string "E8" using the ADDRESS function from the E8 cell reference.

Change the HYPERLINK function formula from

=HYPERLINK("#gid=0&range=E8","Jump")

=HYPERLINK("#gid=0&range="&ADDRESS(ROW(E8),COLUMN(E8),4),"Jump")

Change the #gid=0 part to the actual sheet ID before using.

By combining it with the ADDRESS function like this, ADDRESS(ROW(E8),COLUMN(E8),4) , I was able to make the link follow even if the cell position of "Here it is!" changed due to the addition or deletion of rows or columns.



Using named ranges to link to specific cells relatively

Even though it can be done with the formula above, there are probably many people who are not good at functions or want to do it more easily!

In addition to using the HYPERLINK function + ADDRESS function, you can also create this relative link by using

Named ranges + Insert link

.

A named range is a feature that allows you to assign a name to a specified cell range.


First, select the cell you want to jump to, and then name the cell via Data > Named ranges.

Then, in the source cell, specify the named range using "Insert link".

Unlike links to regular cells, links to named ranges are set up as follows:

They are configured with something called rangeid, making them links specified by rangeid.

Furthermore, since named ranges change relativelyin response to adding or deleting rows and columns, you can create links to specific cells that track these changes.


This might be simpler and easier.



Methods other than hyperlinks for jumping to a specified cell

Finally, I will introduce two methods for jumping to a specified cell other than using hyperlinks.



Jumping using the Name box

One is the method of using the "Name box".

You can jump instantly to a sheet, a specific cell, or a named range.

This "Name box" feature can also be operated using the keyboard shortcut Ctrl + J.

In this way, you can also jump to cells in a named range using only the keyboard.

It is a quite useful feature.



Using the GAS activate method

Another method is to use GAS activate.

For example

function jumpCell(){
  const cellAddress = SpreadsheetApp.getActiveRange().getValue();
  SpreadsheetApp.getActiveSpreadsheet().getRange(cellAddress).activate();
}

By writing code like this and assigning the script to a button, you can jump to a sheet or cell specified by the text in the selected cell.

Personally, I think the name box or hyperlinks are sufficient, so there is no need to go out of your way to use GAS. Just for your reference.



Next time, the final part of the hyperlink series

This time, I wrote about hyperlinks to specific cells within a spreadsheet.

Combining the HYPERLINK function with other functions, or using custom GAS functions to retrieve sheet IDs, the topic expanded more than I had expected.

Next time will be the final part of the hyperlink series.

Examples of using hyperlinks—in this installment, I would like to introduce hyperlinks that can initiate phone calls, hyperlinks that can jump to Google Maps from an address, hyperlinks that can generate search results, and hyperlinks that can generate Gmail templates, among others.









いいなと思ったら応援しよう!

mir チップ大歓迎です。やる気がアップしますw