Creating a Batch Merge Tool in Google Sheets

In Excel, it is easy to select multiple non-contiguous ranges by holding down the Ctrl key and then performing the merge operation effortlessly. However, batch merging in Google Sheets cannot be performed in the usual way. In this article, Officehabit will guide you on how to merge cells in batches effortlessly in Google Sheets.

Batch Merge in Google Sheets with Google Apps Script

To create a batch merge “tool,” the first step is to access Apps Script by selecting Extensions -> Apps Script from the toolbar.

After opening the Apps Script window, copy and paste the following code:

function mergecells() {
  var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
  var select = ss.getSelection().getActiveRangeList().getRanges()
  for (var i = 0; i < select.length; i++){
    select[i].merge()
  }   

}

Then, save and return to the spreadsheet.

Afterward, on the toolbar, select Insert -> Drawing and draw any shape.

Select Save and Close after finishing the drawing to complete.

Next, click on the image, choose Assign Script. Enter the function name created in Apps Script, “mergecells,” and click OK.

Finally, select multiple ranges by holding Ctrl, then click on the created button (image) to merge cells.

You can refer to the test file at the following address:

https://docs.google.com/spreadsheets/d/16ht5MenX_9Jh__i4MWRdriJUG6n26hvv4inBx04bS74/edit?

Leave a Comment

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

Shopping Basket
Scroll to Top