Reputation: 5
https://i.sstatic.net/9CRFd.png I'm trying to use loop to set value "Hello1" in cell F11, "Hello2" in cell F12, "Hello3" in cell F13, then continue until "Hello10". The Cell F10 already has the word "Hello" on it. So far I only managed to show the value "1" on everything
.
Here's how I wrote the script:
function Exercise2() {
var exercise2 = SpreadsheetApp;
var activeSheet = exercise2.getActiveSpreadsheet().getActiveSheet();
var helloCell = activeSheet.getRange(10, 6).getValue();
activeSheet.getRange(1, 1).moveTo(activeSheet.getRange("F10"));
for(var x=10;x<21;x++){
var helloCell = activeSheet.getRange(x, 6).getValue();
helloCell = helloCell+1;
activeSheet.getRange(x, 6).setValue(helloCell);
}
}
Upvotes: 0
Views: 216
Reputation: 16423
The for
loop can be greatly simplified to somthing like this:
for(var x = 1; x < 11; x++) {
activeSheet.getRange(x + 9, 6).setValue("Hello" + x);
}
This will:
1
to 11
stored in x
.x + 9
to the value "Hello" & x
.Upvotes: 1