Freeze rows and columns in Google Sheets using Apps Script

Google Sheets has a useful feature where you can freeze rows and columns to keep them in view as you scroll horizontally or vertically.

In this tutorial I will show you how to freeze rows and columns in Google Sheets using Apps Script. This is especially useful if you are writing data to your spreadsheet via Apps Script and you want to freeze the header row.

The screenshot below shows you a spreadsheet with a single row and column that have been frozen. Therefore, Column A and Row 1 will remain in view even when you scroll.

Screenshot of a Google Sheets spreadsheet with a row and a column that is frozen.

To freeze a row using Apps Script, use the setFrozenRows(N) method of the Sheet object where N is the number of rows at the top to freeze. Similarly, use setFrozenColumns(N) to freeze N columns starting from the left.

function freezeRowsAndColumns() {
  var activeSheet = SpreadsheetApp.getActiveSheet();

To unfreeze rows and columns, use the same method with N set to 0.

function unfreezeRowsAndColumns() {
  var activeSheet = SpreadsheetApp.getActiveSheet();


In this tutorial, I showed you how to use the setFrozenRows() and the setFrozenColumns() methods of the Sheet object to freeze and unfreeze rows and columns in Google Sheets using Apps Script.

Thanks for reading!

Stay up to date

Follow me via email to receive actionable tips and other exclusive content. I'll also send you notifications when I publish new content.
By signing up you agree to the Privacy Policy & Terms.

Have feedback for me?

I'd appreciate any feedback you can give me regarding this post.

Was it useful? Are there any errors or was something confusing? Would you like me to write a post about a related topic? Any other feedback is also welcome. Thank you so much!