Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get url text out of field with HYPERLINK in it

I have a column with hyperlinks formula in it, for example:

=HYPERLINK("http://example.com", "Link")

I want to get additional column, where only urls (as a text) from the first column will be present, that is, in this example:

http://example.com

Is there a function that allows extraction of an url from HYPERLINK? I was thinking also about getting formula text from the first column and cutting it with SPLIT/SUBSTITUTE in the final one, but I'm not sure if I can get one field code into another field.

like image 604
Pawel Markowski Avatar asked Feb 12 '15 09:02

Pawel Markowski


People also ask

How do I extract text from URL in Excel?

Highlight the URL from the Address input in the Edit Hyperlink menu and press Ctrl + C to copy. Press Esc on your keyboard or press the Cancel button to close the Edit Hyperlink menu. Select a new cell and press Ctrl + V to paste the URL into Excel.

How do I convert a hyperlink to plain text?

If you just want to format existing text into a hyperlink: Select the text that you want to turn into a hyperlink, and right-click it. On the shortcut menu, click Hyperlink. In the Insert Hyperlink dialog, paste the link in the Address box and click OK.

How do I extract a URL from a hyperlink in Google Sheets?

Just type =””& and then the cell (no parenthesis) that you want to retrieve the link text from. Then hit Enter.

Can you Vlookup a hyperlink?

To create a hyperlink from a lookup, you can use the VLOOKUP function together with the HYPERLINK function. The hyperlink function allows you to create a working link with a formula. It takes two arguments: link_location and, optionally, friendly_name.


2 Answers

Try this formulas

A2=index(SPLIT(SUBSTITUTE(FORMULATEXT(A1),"=HYPERLINK(""",""),""","""),1,1)

example

A1=HYPERLINK("http://example.com", "Link")

result is

A2=http://example.com
like image 50
mohagali Avatar answered Sep 17 '22 13:09

mohagali


I just created this script and it worked

function URL(reference) {
  var sheet = SpreadsheetApp.getActiveSheet();
  var formula = SpreadsheetApp.getActiveRange().getFormula();
  var args = formula.match(/=\w+\((.*)\)/i);
  
  try {
    var range = sheet.getRange(args[1]).getRichTextValue().getLinkUrl();
  }
  catch(e) {
    throw new Error(args[1] + ' is not a valid range');
  }
  return range;


}
like image 44
Isac Cruz Avatar answered Sep 19 '22 13:09

Isac Cruz