I was trying something in Google Apps Script for my Google Sheets spreadsheet. It basically just copies cells in one sheet, goes to another sheet, pastes it, which updates a bunch of data, then it copies those values, and goes back to the original sheet and transposes those results.
So I had it working as a macro, but I'd like to make it function in a loop, so it fills out all of the rows on a sheet. Below is a copy of my code:
function relcoprow() {
var spreadsheet = SpreadsheetApp.getActive();
var startloc = spreadsheet.getCurrentCell();
var rangetocopy = spreadsheet.getCurrentCell().offset(0,0,1,2);
var countnewcell = 1
var nextcell = spreadsheet.getCurrentCell().offset(countnewcell,0,1,1);
while (nextcell!="") {
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Sheet4'), true);
rangetocopy.copyTo(spreadsheet.getRange("A2"));
spreadsheet.getRange('V1');
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
spreadsheet.getRange('W1').activateAsCurrentCell();
spreadsheet.getRange('V3:V1130').copyTo(spreadsheet.getRange('W3:W1130'),
SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
var rangetotranspose = spreadsheet.getRange('W3:W1130');
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Sheet1'), true);
rangetotranspose.copyTo(startloc.offset(0,7,1,1130), SpreadsheetApp.CopyPasteType.PASTE_NORMAL,
true);
nextcell = nextcell +1
}
};
When I run the code it get's stuck on this line and doesn't move forward. Because it gets stuck I can 't even see if my while loop works.
Can anyone offer advice on what I should do?
nextcell + 1is"Range1"and as it loops it becomes"Range11","Range111"and so on. Absolutely right that it is always true, just thought it was interesting that it is coereced into a string. - dwmorrinwhileloop condition will never be false, but if you want to see this result for yourself, try using the debugger in the script editor. But the loop should run... there's nothing about "getting past a VAR" as your title says... maybe you could define what your trying to accomplish with a minimal example instead of the complex copying? - dwmorrinconsole.logmethod call somewhere above and below the offending line to see if the line is reached at all - Oleg Valterstuckandrejectedmeans, could you by any chance provide a copy of the spreadsheet you're working on, free of sensitive information, so that your issue can be better understood? - Iamblichus