0

I’ve been trying to get this script here to work for a while. Everything has been tested and functions as planned, only if I set the “text” variable to a fixed URL. (There are small kinks, like how it’ll reset the image each time I edit the row, but that isn’t the concern for now. I know how to iron that out later.)
For some reason I just cannot seem to retrieve a URL (no hyperlink formula) or any text for that matter, and have it be inserted with this formula. The text replace functions properly if I use a specific URL, for example, “var text = “put URL here”, but how can I have “var text” become a URL inside a cell and then inserted along with that formula? I have scoured the internet for hours and tried so many different variations on getValue, getLinkUrl, copying text, etc., as well as ways to set the value, but have had no luck.

The concept: Easily adding hyperlinked images simply by pasting a URL into a cell.

My script: [1]: https://i.sstatic.net/F1xkG.png

2
  • Note: When I do not simply use a specific URL, but instead attempt to retrieve one and reference it, the formula will not even set in the cell when I edit the row.
    – IsaacFrye
    Commented Aug 2, 2021 at 2:52
  • Welcome to Web Applications Stack Exchange. Is this an XY problem? Commented Aug 2, 2021 at 9:16

1 Answer 1

1

Your code will throw an error in sh.getRange(copycell).getLinkUrl() in line 7. Replace it with copycell.getRichTextValue().getLinkUrl() to solve the issue.

The code suggests that you are always pasting URLs in column F and always want to see the hyperlinked image in column H. It is unclear why you would need to use an onEdit(e) script for this in the first place. Try something like this in row 2 of a free column:

=arrayformula( iferror( hyperlink(F2:F, image(F2:F)) ) )

If the links you are pasting are not URLs but rich text links, use the RichTextLinks custom function and this formula:

=arrayformula( ( hyperlink( RichTextLinks("F2:F", F2:F), image(RichTextLinks("F2:F", F2:F)) ) ) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.