When I change a getRange('D4')
command to a getRange(i,4)
or even getRange(4,4)
I get the error:
Cannot find method getRange(number,number)
I am editing a Google Sheets macro function that intends to copy data from a known cell 'G6' to a given row (i) in column D (in this particular instance 'D4') based upon matching an index in column C to determine the row i.
I believe the for-loop correctly identifies the row correctly, but please tell me if there is an obvious issue with this.
spreadsheet.getRange(i,4).activate();
because it returns the titled error
Cannot find method getRange(number,number).
I also get this error if I try
spreadsheet.getRange(4,4).activate();
however, there is no issue when I run
spreadsheet.getRange('D4').activate();
which is where I began to record a macro.
function CopyMacro() {
var spreadsheet = SpreadsheetApp.getActive();
var data = spreadsheet.getDataRange().getValues();
var playerID = spreadsheet.getRange("F3").getValue();
var playerID2 = spreadsheet.getRange("F6").getValue();
spreadsheet.getRange('I3').activate();
spreadsheet.getRange('G3').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
for(var i = 0; i<data.length;i++){
if(data[i][2] == playerID){
spreadsheet.getRange(i,4).activate();
spreadsheet.getRange('G6').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
}
}