Copying the value of a cell in Google Sheets only if a different cell is not empty

If you want to filter out blank cells in Excel, the accepted answer is effective. However, it may not work if the cells contain formulas that evaluate to blank. In this case, ISTEXT will return TRUE and the blanks won’t be filtered out. To address this issue, you could use the default check for ISBLANK. Alternatively, you could follow Solution 1 and filter out rows with blank cells in column D. Just keep in mind that the second argument would also need to be filtered to ensure the ranges are the same length.


Solution:

Begin by utilizing a script that is alike to this one.

function copyVals() {
  let ss = SpreadsheetApp.openById("ID");
  let sheet1 = ss.getSheetByName("Sheet1");
  let sheet2 = ss.getSheetByName("Sheet2");
  let colA = sheet1.getRange('A:A');
  if (!colA.isBlank()) {
    let valToPaste = sheet2.getRange(1,1).getValue();
    sheet1.getRange(1,2).setValue(valToPaste);
  }
}

To ensure that the desired column is not blank, the

isBlank

function is utilized. If the verification is successful, the value from

Sheet2!A1

is copied into

Sheet2!B1

using the

valToPaste

method.

Note
  • You may need to add a

    for

    loop, depending on your exact needs.

  • Since you mentioned you are using a form, you may want to check Apps Script triggers.

Reference
  • The isBlank() method of the Range class in Apps Script.

Frequently Asked Questions