I have a script runing which uses IMPORTDATA to capture data from a website. Every hour it goes to the website, and captures a price value, and pasts it into a cell for that hour. So each dat I ended up with 24 cells on a row, populated.
The problem I have is that every hour, EVERY cell is being updated.
So imagine it runs at 11pm and the result is 5,500. What happens is that every single cell that has previously populated changes to 5,500.
From what I understand, it seems like IMPORTDATA is syncing with the websit every hour. This isnt what I want....I would like it so that once the data is imported using importdata, the link is broken and the data never changes.
Does anyone know how I can alter my code to achieve this?
Thanks guys.
function pricesearchsheet2() {
var date = new Date();
var currenthour = date.getHours();
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
var targetcell = 1
// set the target cell based on the current hour of the day
if (currenthour == 0) {
var targetcell = "B6";
}
if (currenthour == 1) {
var targetcell = "C6";
}
if (currenthour == 2) {
var targetcell = "D6";
}
if (currenthour == 3) {
var targetcell = "E6";
}
if (currenthour == 4) {
var targetcell = "F6";
}
if (currenthour == 5) {
var targetcell = "G6";
}
if (currenthour == 6) {
var targetcell = "H6";
}
if (currenthour == 7) {
var targetcell = "I6";
}
if (currenthour == 8) {
var targetcell = "J6";
}
if (currenthour == 9) {
var targetcell = "K6";
}
if (currenthour == 10) {
var targetcell = "L6";
}
if (currenthour == 11) {
var targetcell = "M6";
}
if (currenthour == 12) {
var targetcell = "N6";
}
if (currenthour == 13) {
var targetcell = "O6";
}
if (currenthour == 14) {
var targetcell = "P6";
}
if (currenthour == 15) {
var targetcell = "Q6";
}
if (currenthour == 16) {
var targetcell = "R6";
}
if (currenthour == 17) {
var targetcell = "S6";
}
if (currenthour == 18) {
var targetcell = "T6";
}
if (currenthour == 19) {
var targetcell = "U6";
}
if (currenthour == 20) {
var targetcell = "V6";
}
if (currenthour == 21) {
var targetcell = "W6";
}
if (currenthour == 22) {
var targetcell = "X6";
}
if (currenthour == 23) {
var targetcell = "Y6";
}
if (currenthour == 24) {
var targetcell = "Z6";
}
for (var sheet of sheets) {
sheet.getRange(targetcell)
.setValue('=--SPLIT(REGEXEXTRACT(JOIN(",",IMPORTDATA(B1)),"LCPrice"":""(.*)"), CHAR(34))')
}
}