Question

Is it possible to use a captured value inside a getRange(value) code? If so, what do i need to change here? It keeps failing on the last line of code and i have tried a few different options.

function test(row) { 
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();// Define active sheet
  var amountdue = sheet.getRange("A30").getValue();// Capture amount due
  var rownumber = sheet.getRange("A30").getValue();// Capture row number
  sheet.getRange("B30").setValue(amountdue);// Paste amount due
  sheet.getRange("C"&rownumber).setValue(amountdue);// Paste amount due using captured row number
}
Was it helpful?

Solution

try that code:

function test(row) { 
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();// Define active sheet
  var amountdue = sheet.getRange("A30").getValue();// Capture amount due
  var rownumber = sheet.getRange("A30").getRow()// Capture row number
  sheet.getRange("B30").setValue(amountdue);// Paste amount due
  sheet.getRange(rownumber,3).setValue(amountdue);// Paste amount due using captured row number
}

What I corrected:
when you are trying to get the row use the formula getRow().
When you are trying to set the value to a cell with the retrieved row use the formula getRange(Integer row,Integer column) to point the good cell.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top