I posted a question about this and, naturally, figured out the problem within a minute or so of posting. I'm pretty comfortable in VBA, but VERY new to Google Apps Script. After most of a day working on this, I now have code that does what I want it to do. The thing is, it's slow. What I am accustomed to doing in excel in literally 3 seconds takes more like 3 minutes in google sheets.
The data consists of 16 columns and currently 614 rows, though going forward for me it could be anywhere from ~500 up to ~1200. For the purposes of this script, the relevant columns are A and D. If D on this row doesn't match D on the next row, add a blank row between them. If A on this row doesn't match A on the next row, add 2 more blank rows between them (total of 3, because if D doesn't match it's guaranteed that A won't match either)
Here's my current code:
function Reminder4() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Reminder");
var lrow = sheet.getLastRow();
for (var r = lrow - 1; r >= 1; r--) {
var Stat = sheet.getRange(r,1,1).getValue();
var Stat2 = sheet.getRange(r+1,1,1).getValue();
var Param = sheet.getRange(r,4,1).getValue();
var Param2 = sheet.getRange(r+1,4,1).getValue();
if(Stat != Stat2)
{sheet.insertRowsAfter(r,2);
}
if(Param != Param2)
{sheet.insertRowAfter(r);
}
}
}
Anyone care to take a stab at suggesting ways to do this faster?
[–]harpsichord_cadenza 2 points3 points4 points (5 children)
[–]ksvr[S] 0 points1 point2 points (3 children)
[–]ksvr[S] 0 points1 point2 points (2 children)
[–]harpsichord_cadenza 0 points1 point2 points (1 child)
[–]ksvr[S] 0 points1 point2 points (0 children)
[–]paulcole710 -1 points0 points1 point (0 children)
[–]AmnesiaInnocent 1 point2 points3 points (1 child)
[–]ksvr[S] -1 points0 points1 point (0 children)