Search code examples
google-sheets

How to concat text in each cell but sometimes there's more than 1 line of text per cell


I am trying to have each line of links have "http://" in the beginning of each URL. The issue is that I am using this formula =IF(A2<>"", "http://"&A2,"") but it does not work if there's more than 1 URL in a cell. Is it possible to concatenate every line of URL even if there is 3 URL in 1 cell?

enter image description here

Example GSheet Link.


Solution

  • =arrayformula(map(A2:A5,lambda(each,join(char(10),"http://"&split(each,char(10))))))
    

    This inserts 'http://' in front of each link irrespective of the number of links per cell, however if for those cells with multiple links you wanted to generate the corresponding multiple hyperlinks per cell this is impossible using a formula as the HYPERLINK function only allows one link per cell. It's possible when manually inserting links, and I assume it's doable with a script as well.