Find Last Row of a Specific Column

How to find the last row of a specific column, rather than the entire sheet.

Important notes:
* Make sure the variable used to store the row is declared and instantiated outside and above the FOR() loop so that it can be accessed and used outside and below the FOR() loop. Otherwise you have to declare another variable just to hold the ending FOR() loop value.
* Make sure the row value is incremented once more before using it as the target sheet range, or you will override the current last row of data rather than adding a new row of data.

Sheet (to copy):

function onEdit(e) {
var s = e.source.getActiveSheet();
if(s.getName() != “Purchases” || e.range.columnStart != 6 || e.value != “X”) return;
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“Cleared”);

var cData = targetSheet.getRange(1,1,targetSheet.getLastRow()).getValues();
var c = 0;
for (c; c < cData.length; c++){
if (cData[c][0] == “”)

if (c == targetSheet.getMaxRows())

var r = e.range.rowStart;
s.getRange(r,1,1,5).copyTo(targetSheet.getRange(c,1,1,5), {contentsOnly:true});


Leave a Reply

Your email address will not be published. Required fields are marked *