index ()

62 views
Skip to first unread message

Doctor Burry

unread,
Dec 4, 2022, 7:31:14 AM12/4/22
to Google Apps Script Community
Please help me.

This works fine: =IMPORTXML(CONCATENATE("https://finance.yahoo.com/quote/"; index(A1));"/html...

This does not work:

var col="A1"
=IMPORTXML(CONCATENATE("https://finance.yahoo.com/quote/"; index(col));"/html...

why can't i use a variable inside index()

how could i do it?

 A lots thanks in advance for any info

Edward Ulle

unread,
Dec 4, 2022, 10:52:29 AM12/4/22
to Google Apps Script Community
You post is confusing.  You show a formula where you are trying to concatenate "https://finance.yahoo.com/quote/" with the value in cell A1, I'm assuming a stock symbol.

But then you show a script.  Are  you trying to build a formula in script editor to be placed in a cell?  If so it should be something like this.

var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");  // what ever sheet you want
var col = "A1";
var value = sheet.getRange(col).getValue();
var formula = '=IMPORTXML(CONCATENATE("https://finance.yahoo.com/quote/"; '+value+';"/html...")';
sheet.getRange("B1").setFormula(formula);

Notice the use of double quotes within the formula and single quotes to define the substrings being joined together to form the formula.

cbmserv...@gmail.com

unread,
Dec 4, 2022, 11:25:40 PM12/4/22
to google-apps-sc...@googlegroups.com

Did you resolve this issue? Can you share the final code?

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/4ad32467-fce8-41a0-949d-72477d1c57abn%40googlegroups.com.

Doctor Burry

unread,
Dec 5, 2022, 5:01:36 AM12/5/22
to Google Apps Script Community
Thank you very much for your help. Starting from the example I got it to work fine. I'm very happy.
Reply all
Reply to author
Forward
0 new messages