I’m encountering an unexpected behavior with a script I’m using. It worked successfully yesterday, but today it’s not functioning as expected. I’ve already run a debug on the code and found no apparent issues.
The script is designed to perform the following tasks:
Retrieve data from the “Price” sheet.
For all other sheets, extract data only from rows starting at row 2, specifically from columns B and C.
Subsequently, the script should insert this data into the respective sheets.
Additionally, it should locate the last rows in these sheets where there is a date in column B, but no data present in columns H and I.
If these conditions are met, the script should insert the data.
Current Challenge:
I’m puzzled as to why the script, which operated correctly yesterday, is now experiencing this issue. I’ve reviewed the code in detail and can’t identify any apparent problems.
https://docs.google.com/spreadsheets…it?usp=sharing
function copyDataFromPriceToAllSheets() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var priceSheet = ss.getSheetByName("Price");
var sheetRanges = {
"Centus": "B3:C3",
"CentusBNB": "B3:C3",
"Plus": "B2:C2",
"Binc": "B4:C4",
"Bincin": "B5:C5",
"Bincpl": "B6:C6",
"Bincru": "B7:C7",
"Bincua": "B8:C8",
"Bincome": "B9:C9",
"BincomeBNB": "B9:C9"
};
for (var sheetName in sheetRanges) {
var sheet = ss.getSheetByName(sheetName);
var range = sheetRanges[sheetName];
// Get the data from Price sheet using the specified range
var data = priceSheet.getRange(range).getValues()[0];
// Remove the dollar sign from column H
if (data[0]) {
data[0] = parseFloat(data[0].replace('$', ''));
}
// Format column I as percentage (multiply by 100 and round to 2 decimal places)
if (data[1]) {
data[1] = (parseFloat(data[1]) * 100).toFixed(2) + "%";
}
var lastRow = sheet.getLastRow();
// Get all data in columns B, H, and I
var rangeData = sheet.getRange(2, 2, lastRow - 1, 3).getValues();
for (var i = 0; i < rangeData.length; i++) {
var rowData = rangeData[i];
// Check if there is no data in columns H and I in the current row with a date
if (rowData[0] !== "" && rowData[1] === "" && rowData[2] === "") {
// Set the data in the sheet columns H and I on the current row with a date
sheet.getRange(i + 2, 8, 1, 2).setValues([data.slice(0, 2)]);
}
}
}
}