Automatically resize rows & columns in Google Sheets using Apps Script

Last updated: February 09, 2025

In this tutorial, I will show you how easy it is to automatically resize rows and columns in Google Sheets using Apps Script. This can be useful when you automate importing CSV files into Google Sheets using Apps Script since you can automatically resize the rows and columns in the sheet after importing data.

Automatically resize columns in Google Sheets using Apps Script

To automatically resize a single column, use the autoResizeColumn(columnNumber) method of the Sheet object and specify which column to resize. The width of this column will be automatically adjusted based on the text contained in that column.

The code below resizes the first column (i.e., Column A).

function autoResizeSingleColumn() {
 SpreadsheetApp.getActiveSheet().autoResizeColumn(1);
}

To automatically resize multiple columns, use the autoResizeColumns(startColumn, numColumns) method. The width of these columns will be automatically adjusted. The video below shows an example of the first two columns being automatically resized.

The method autoResizecolumns() needs two parameters: startColumn and numColumns. If these are 2 and 3, then 3 columns starting from the 2nd column will be automatically resized.

function autoResizeMultipleColumns() {
 SpreadsheetApp.getActiveSheet().autoResizeColumns(2,3);
}

Automatically resize rows in Google Sheets using Apps Script

To automatically resize rows, use the autoResizeRows(startRow, numRows) method and specify which rows to resize. The height of these rows will be automatically adjusted.

The method autoResizeRows() needs two parameters: startRow and numRows. If these are 3 and 5, then 5 rows starting from the 3rd row will be automatically resized.

function autoResizeMultipleRows() {
 SpreadsheetApp.getActiveSheet().autoResizeRows(3,5);
}

Conclusion

In this tutorial, you learned how to automatically resize rows and/or columns in Google Sheets using Apps Script.

Thanks for reading!

DISCLAIMER: This content is provided for educational purposes only. All code, templates, and information should be thoroughly reviewed and tested before use. Use at your own risk. Full Terms of Service apply.

Small Scripts, Big Impact

Join 1,500+ professionals who are supercharging their productivity with Google Sheets automation

Exclusive Google Sheets automation tutorials and hands-on exercises
Ready-to-use scripts and templates that transform hours of manual work into seconds
Email updates with new automation tips and time-saving workflows

By subscribing, you agree to our Privacy Policy and Terms of Service