Using Google Apps Script to Copy Data to Empty Rows in Google Sheets

I’m looking for assistance with a Google Apps Script to automate the process of copying a specific range of cells into empty cells in my Google Sheet. Here’s what I need:

  1. Copy the range of cells from T4 to BE4 (shown in the green box).
  2. Paste these values into the next available empty rows where there’s data in Column A, but Column T is blank.

Since I’m not sure how to get started with the script, any help or example would be greatly appreciated, whether it runs automatically or via a button.

First, identify your target rows, then copy the source data in one go. Use getValues() to grab the entire dataset at once - don’t do cell-by-cell operations since they’re way slower. Pull all values from columns A and T, then filter for rows where A has content but T is empty. Once you’ve got those row numbers, use setValues() to paste your T4:BE4 range to each target row. Batch operations like this work much better than updating individual cells, especially with bigger datasets. You can trigger the script manually with a custom menu or button, or set it up as a time-driven trigger if you want it automated.

Here’s what worked for me in a similar situation: I set up a simple function that grabs the source range values with getRange(‘T4:BE4’).getValues(), then scans through the sheet to find matching rows. I start from row 5 since your template data’s in row 4. The trick is checking both conditions at once - column A isn’t empty AND column T is empty - before pasting. So if(dataA !== ‘’ && dataT === ‘’) then use setValues() to paste your captured range. I’d add some error handling around the paste operation since the target range might be protected or have validation rules. Running it through a custom menu option gives you way more control than automation, especially when you’re testing the logic.

hey john, you might wanna use a loop for findin the rows where A has data but T is blank. just use getLastRow() and check with if(sheet.getRange(i,1).getValue() && !sheet.getRange(i,20).getValue()). then paste your range there! super easy!