-1

I have a simple Google sheet retrieving Stock Data using =Googlefinance(ticker,"close",today()-7,today()) in cell A2 (and the ajacent range). When I try to read the retrieved data in a script using sheet.range("A2").getValue() the script returns "#N/A" in cell A2 although it clearly has the word "Date" in it. All other values in the range return an empty value when retrieved through sheet.getRange().getValue(). Is there any way to retrieve the Googlefinance() data with getValue()?

When I fill the range with values (paste as values) everything works well... it looks like getValue() cannot read Googlefinance() data.

function UpdateRange() {
var sheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
//cell A2 contains formula GOOGLEFINANCE("AAPL","close",today()-7,today())
var fTitle = sheet.getRange("A2").getValue();
//returned value is #N/A
var fDate = sheet.getRange("A3").getValue();
//returned value is an empty string
Logger.log(fTitle); 
Logger.log(fDate);
}

The getValue() statement should return the actual value of the cell, not #N/A or empty cells.

player0
  • 124,011
  • 12
  • 67
  • 124

1 Answers1

0

When you specify a date range the result is not displayed in the formula cell. Instead, it's displayed in the adjacent cells to the left and below.

enter image description here

Cooper
  • 59,616
  • 6
  • 23
  • 54