Google spreadsheet formula for url with a variable

10,079

Solution 1

In Excel, you'd do something like the following. Give it a try in a google spreadsheet.

=importXML("http://www.xxx.it/code/" & B3 & "/doc/book.html","//span[@class='description']")

Solution 2

Use CONCAT in Google Sheets.

=CONCAT("http://www.xxx.it/code/(", $B2,")/doc/book.html")

You may need a formula to get the exact spot in the string.

Share:
10,079
Barbara
Author by

Barbara

Updated on June 07, 2022

Comments

  • Barbara
    Barbara almost 2 years

    What's the formula to display an url in google sheet when part of said url is a variable from another cell?

    I'll explain: in one cell I have this formula (used to scrape text with class 'description' in an html webpage, doesn't matter for the purpose of the question though) =importXML("http://www.xxx.it/code/9788823506183/doc/book.html","//span[@class='description']")

    The numerical part changes everytime based on the value in another cell, say B3. Tried =importXML("http://www.xxx.it/code/(B3)/doc/book.html","//span[@class='description']") but of course it won't work.

    Then I thought I could dinamically create the url in B2 and do like this: =importXML("B2","//span[@class='description']")

    One step closer but I'm stuck anyway, how can I generate such url in B2? I can't find a suitable function in the docs. I could only come up with:

    in A1 = 9788823506183

    in B2 = http://www.xxx.it/code/("A1")/doc/book.html but it's not the correct syntax. :(