Unmerge all cells in sheet - apps script

PHOTO EMBED

Mon Feb 14 2022 00:46:23 GMT+0000 (Coordinated Universal Time)

Saved by @dsottimano #appscript

function unmergeAllCells() {
  let app = SpreadsheetApp;
  let activeSheet = app.getActiveSpreadsheet().getActiveSheet();

  let lastrow = activeSheet.getLastRow();
  let lastCol = activeSheet.getLastColumn();
  
  for (column = 1; column < lastCol; column++){
  let mergerange = activeSheet.getRange(1,column,lastrow).getMergedRanges();
  mergerange.map(cells => cells.breakApart())
  }

}
content_copyCOPY

Adapted from https://stackoverflow.com/questions/17355148/unmerge-in-google-apps-script