0
votes

I am running a function which I am trying to find the value for the last row, last column of a sheet and use this value as part of a range value. In my test sheet, the last column, last row value is the number 3. Lines 45 and 46 are from another function I am using on the same sheet to rename the active sheet. This function works OK, i.e., the script finds the number 3 and renames the active sheet to 3. Line 56 shows that the script works properly when using static values. Line 57 is my attempt to use the getLastRow and getLastColumn method to insert this number as part of the getRange values. When I run this script, it throws an error “Range not found”. The “Logger.log” value at Line 55 is 3.0 and shows that the script is running up to that point. I conclude that the error is coming from Line 57. Questions: 1. Am I trying to do something that cannot be done by using the (lastCell, getValue()) value? As mentioned, the value is 3.0 and not just 3, but this works for Lines 45 and 46. 2. If this can be done, am I formatting the information incorrectly? I have also tried to write Line 57 as (‘A:A+(lastCell.getValue())’) by adding the “+” sign. Thanks for any assistance!

45  // SpreadsheetApp.setActiveSheet(ss.getSheetByName('Copy of Sheet1'));  
46  // SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet(lastCell.getValue()); This works OK!!!
47  //
48  // Next need to make the next row have columnA and last Column data added
49  //
50  var ss = SpreadsheetApp.getActiveSpreadsheet();
51  var sheet = ss.getSheetByName('Master FCR Listing');//ss.getSheets()[1];
52  var lastColumn = sheet.getLastColumn();
53  var lastRow = sheet.getLastRow();
54  var lastCell = sheet.getRange(lastRow, lastColumn);
55  Logger.log(lastCell.getValue());// Shows a value of 3.0 ??  This the problem?? 
56  //*  sheet.getRange('A:A3').copyTo(sheet.getRange('A:A4')); //. This works!
57  sheet.getRange('A:A(lastCell.getValue())').copyTo(sheet.getRange('A:A4'));//A4 will be +1!
1

1 Answers

0
votes

Replace

sheet.getRange('A:A(lastCell.getValue())') 

to

sheet.getRange('A:A'+(lastCell.getValue()))

to pass the range in format of string.