Copy the text of a cell after an hyperlink click to another cell

Viewed 45

I have a list and all the text is hyperlinked to the same cell in the same sheet.

Is there any way to copy the text of the cell you've clicked to the other cell?

  A                                                                B
=HYPERLINK("...range=B1";"apple")                                                           
=HYPERLINK("...range=B1";"banana")
=HYPERLINK("...range=B1";"pear")
=HYPERLINK("...range=B1";"melon")
1 Answers

Explanation:

Your goal is to click/select a cell and get the value copied to the next cell in the same row.

Solution:

Copy this code to the script editor:

function onSelectionChange(e) { 
  if(e.range.getColumn()==1){
     e.range.offset(0,1).setValue(e.range.getValue());
  }
}

Illustration:

enter image description here

Updated code based on OPs comment:

Copy all hyperlinks to cell B1:

function onSelectionChange(e) { 
  if(e.range.getColumn()==1){
    e.source.getActiveSheet().getRange('B1').setValue(e.range.getValue());
  }
}

Please Note!

Users have reported in the IssueTracker that onSelectionChange trigger does not work for them and it didn't work for me either. However, after I tried the recommendation steps by the google guy (you can find them in the link also) it worked:

However, I managed to get the trigger to work correctly by deactivating V8 runtime, closing the Apps Script project and the document, and finally, reopening the document and reactivating the V8 runtime.

Related