1.1 ๐Ÿ“Œ Emojis in Google Sheets

Google Apps Script: Remove Emojis from Google Sheet

const replaceEmojisInGoogleSheet = () => {
  SpreadsheetApp.getActiveSpreadsheet()
    .getSheets()
    .filter((sheet) => sheet.getType() === SpreadsheetApp.SheetType.GRID)
    .filter((sheet) => sheet.isSheetHidden() === false)
    .forEach((sheet) => {
      sheet
        .getDataRange()
        .getValues()
        .forEach((row, rowIndex) => {
          row.forEach((cell, colIndex) => {
            if (typeof cell === 'string' && /\p{Emoji_Presentation}/u.test(cell)) {
              sheet
                .getRange(rowIndex + 1, colIndex + 1)
                .setValue(cell.replace(/\p{Emoji_Presentation}/gu, ' ').trim());
            }
          });
        });
    });

  SpreadsheetApp.flush();
};

Step-by-Step Explanation

replaceEmojisInVisibleSheets()

This is the main function. It retrieves all sheets, filters only the visible grid-type ones, and processes them one by one using processSheet. It finishes by flushing all pending changes with SpreadsheetApp.flush().

isVisibleGridSheet(sheet)

Checks whether a sheet is a normal spreadsheet (not a chart or dashboard), and confirms it is not hidden. Returns true only for visible grid-type sheets.

processSheet(sheet)

- Gets all values from the current sheet.
- Iterates over each cell in each row.
- Replaces emojis only in string cells using removeEmojis.
- Writes the updated values back in one batch (more efficient than writing cell-by-cell).

removeEmojis(text)

Uses a Unicode regular expression \p{Emoji_Presentation} to match emojis.
Replaces emojis with a space and trims leading/trailing spaces.


ยฉ 2025 ExcelQuickGuide.com โ€ข Helping Poor Students