Google-sheets – Google sheets, how to combine data from two cells, where there is a URL (web-link) in the cells, without loosing the link(url)

formulasgoogle sheetsgoogle-apps-scriptgoogle-sheets-custom-function

I have tried to write a custom function in google sheets.

I tried to create a function to joint the content of two cells. It works for text, however it does not work if the text contains a web-link (URL). The link is removed.

The code

function combine(...theArgs) {
  var result ="";
  var is_first = true;
  theArgs.forEach( function (value, index){
    if (! is_first) {
      result += "\n\n";
    }
    is_first=false;
    result += value;
  });
  return result;
}

Usage =combine(ref, ref) e.g. =combine(a1,b1)

I tried to use =hyperlink(url,text), this can combine the text and link from different cells, so I then tried =hyperlink(url1, text1) & hyperlink(url2, text2). The & is demoting the link to text (removes the url).

Acceptable answers:
– How to get a custom function to work.
– Use of built in function.
– Something else that has the same effect.

Best Answer

It don't think that it's possible to do what you are looking to do with a custom function, as in order to keep the hyperlinks, you will need to set the cell content by using Class RichText which, as far as I know, is not a supported data type for custom functions.

The supported data types for custom function output are string, number, boolean, Date and Array of any of the mentioned data types.