Can Google Sheets Freeze Rows Based on Cell Values?

How-to basics · Updated November 3, 2026

Can Google Sheets Freeze Rows Based on Cell Values?

No—Google Sheets cannot natively freeze or unfreeze rows automatically according to a cell’s value. You can freeze a chosen number of rows manually with View > Freeze, or use a small Google Apps Script to change the frozen rows when a user edits a cell or a marker in the sheet.

What “freeze rows based on a value” means

Freezing rows keeps them visible at the top of the sheet while you scroll down. It is a display setting, not a rule that changes which records are in the sheet. A common request is to keep the header visible, but the desired boundary may depend on the data: perhaps the header ends at a row marked HEADER END, or the number of rows to keep is entered in a settings cell.

Those are different kinds of automation. A number in a control cell can tell a script how many rows to freeze. A label in a column can tell it which row marks the end of a section. Google Sheets’ ordinary Freeze command does not interpret either value; it freezes the rows selected by the user. A formula, conditional-formatting rule, or filter does not add this behavior to the Freeze command.

This distinction matters because freezing is not the same as hiding rows. A frozen row remains part of the sheet and stays visible as you scroll. Hiding rows removes them from the current view until they are unhidden. Freezing also does not keep a row visible only when a condition is true; it pins a fixed number of top rows.

What Google Sheets can freeze without a script

In Google Sheets in a web browser, use View > Freeze and choose a preset such as 1 row or 2 rows. To freeze through a different row, select a cell in the row that should be the last frozen row, then use View > Freeze and choose the option to freeze up to the selected row. The exact row number shown in that menu depends on your selection. To remove the setting, use View > Freeze > No rows.

You can also adjust the gray freeze divider near the top-left of the grid by dragging it, where that divider is available in the current interface. The menu is more precise when you need to freeze a known number of rows. To freeze columns instead, use the corresponding choices under View > Freeze.

For example, if row 1 contains column labels and rows 2 through 500 contain sales records, freezing 1 row keeps the labels visible while you scroll through the records. If the first three rows contain a title, a date range, and column labels, freeze through row 3. The choice remains in effect until someone changes it; it does not move automatically if rows are inserted, deleted, or relabeled in a way that changes where your logical header ends.

How to freeze rows manually

For a sheet with a stable layout, a manual freeze is usually the simplest and most dependable solution. It takes only a few steps:

  1. Open the sheet in Google Sheets in your browser.
  2. Decide how many top rows need to stay visible while scrolling.
  3. Choose View > Freeze, then select 1 row, 2 rows, or the option that freezes up to the row you selected.
  4. Scroll down to check that the intended headings remain visible.
  5. If the wrong rows are pinned, return to View > Freeze and choose a different boundary or No rows.

Manual freezing is appropriate when the header is always in the same place and collaborators do not need the boundary to change with the content. It is also preferable when the sheet should not run scripts. If several people edit the spreadsheet, explain which rows are frozen; someone can change the view setting without changing any cell values, and that can make the sheet appear different to another user.

Ways to automate a value-based freeze

If the boundary really does change based on data, Google Apps Script can set the number of frozen rows. A useful approach is to put a clear marker, such as END HEADER, in column A on the last row that should remain visible. A script can look for that marker and freeze through its row. This avoids hard-coding a row number that may become outdated when the layout changes.

Another approach is to put a whole number in a dedicated settings cell, such as Settings!B2, and have a script read that value as the number of top rows to freeze. This is convenient if a user should choose the count directly. In either design, the script changes the sheet’s freeze setting; it does not make the Freeze menu itself conditional, nor does it evaluate the value continuously in the background.

Choose a marker or settings cell that will not be confused with ordinary data. Document what it controls, and agree with collaborators on what should happen if the marker is missing, duplicated, blank, or contains an invalid number. Those decisions prevent a mistaken edit from unexpectedly unfreezing the sheet or pinning dozens of rows.

Example: freeze through a marker row with Apps Script

The following bound script looks for the exact text END HEADER in column A. When a user edits column A, it freezes all rows from the top through the first matching marker. If the marker is not found, it freezes no rows. To add it, open Extensions > Apps Script from the spreadsheet, paste the code into the project, and save. The function is named onEdit, so it runs as a simple edit trigger when a user edits the sheet; it does not need to be deployed as a web app.

function onEdit(e) {
  const sheet = e.range.getSheet();

  // Recheck the marker only when the edit touches column A.
  if (e.range.getColumn() > 1 || e.range.getLastColumn() < 1) return;

  const lastRow = sheet.getLastRow();
  if (lastRow === 0) {
    sheet.setFrozenRows(0);
    return;
  }

  const labels = sheet.getRange(1, 1, lastRow, 1).getDisplayValues();
  let rowsToFreeze = 0;

  for (let i = 0; i < labels.length; i++) {
    if (labels[i][0] === 'END HEADER') {
      rowsToFreeze = i + 1;
      break;
    }
  }

  sheet.setFrozenRows(rowsToFreeze);
}

In this example, if END HEADER is in A4, the script freezes rows 1 through 4, including the marker row. If it is in A1, only row 1 is frozen. If there is no exact match, setFrozenRows(0) removes the frozen rows. If the marker appears more than once, the loop uses the first match from the top. Change the marker text in the code and the sheet together if you want to use a different label.

The event object e is supplied by the edit trigger; running onEdit directly from the Apps Script editor will not provide that event object. To test it, edit a cell in column A in the spreadsheet. The code checks only edits that touch column A, so edits elsewhere do not rescan the marker. A paste that includes column A does count as an edit to that column.

Important limits and common problems

A simple onEdit trigger responds to a user’s direct edit, not to every possible change in a cell’s displayed value. In particular, a formula recalculating, an import refreshing, or another script or API changing a value does not fire the simple edit trigger in the same way as a person typing into the cell. If your marker is produced by a formula, this example will not reliably update the freeze boundary when the formula result changes. You would need a different design, such as a time-driven or installable trigger where appropriate, or a manual refresh control.

Also consider the behavior of your spreadsheet’s collaborators. A script that calls setFrozenRows changes the frozen-row setting for that sheet, so a user who expected to keep a different boundary may find it changed after editing the marker. Protecting the marker cell, explaining its purpose, and testing on a copy can reduce surprises. A simple trigger has restrictions: it cannot use services that require authorization, and it is not a general-purpose way to monitor every event in a spreadsheet.

If the script appears not to work, check that it is bound to the correct spreadsheet, that the function is named exactly onEdit, that the marker text matches including spaces and capitalization, and that the edit was made in column A. Check the Apps Script execution details for errors. Also make sure the marker is within the sheet’s populated range; the example searches only through getLastRow().

Alternatives when freezing is not the right tool

If the real goal is to show only rows matching a value, use a filter rather than a freeze. Select the data range and choose Data > Create a filter, then use the filter controls in the header to display records that meet the desired condition. A filter changes which records are visible; it does not pin rows at the top. Filter views can be useful when different collaborators need separate ways to inspect the same data.

If you want to call attention to a row when a cell meets a condition, use Format > Conditional formatting. That can change a cell’s appearance, but it cannot freeze the row. If you need to make a row disappear based on a value, you can hide it manually or use Apps Script to hide rows, but hiding is a different action and can make data harder for collaborators to find. Pick the feature that matches the goal: freeze for persistent headings, filter for selecting records, and conditional formatting for visual emphasis.

Google Sheets and Excel behave differently

Google Sheets’ browser interface uses View > Freeze, while Excel for Microsoft 365 on Windows uses the View tab’s Freeze Panes controls. Both programs can keep a fixed number of top rows visible, but neither standard freeze command is a built-in rule that checks a cell value and automatically changes the boundary. Excel can be automated with tools such as VBA, while Google Sheets can be automated with Apps Script; the code and trigger models are different and are not interchangeable.

If a workbook is downloaded from Sheets and opened in Excel, do not assume a Sheets Apps Script will follow it. Apps Script belongs to Google Sheets, while Excel automation must use an Excel-supported method. For a shared workflow, choose the platform where the spreadsheet will actually be edited and implement the automation there.

Frequently Asked Questions

Can Google Sheets freeze a row when a cell equals a specific value?

Not with a built-in conditional freeze setting. You can use Apps Script to search for the value and call setFrozenRows, or freeze the desired rows manually. The script must be designed for the kind of change that updates the cell.

Can I freeze rows based on a formula result?

Not automatically with the standard Freeze menu. A simple onEdit trigger does not run merely because a formula recalculates. A script-based solution needs another way to notice or check the formula result, such as a suitable scheduled check or a user-operated refresh step.

Can Google Sheets freeze a row in the middle of a sheet?

The Freeze feature pins rows from the top of the sheet; it does not pin an isolated middle row while leaving the rows above it unpinned. You can freeze through a selected row, which includes every row above it. To keep a middle section visible, consider reorganizing the sheet or using a separate summary or report area.

Will a filter or conditional formatting rule freeze rows?

No. Filters show or hide records based on criteria, and conditional formatting changes how cells look. Neither feature changes which top rows are frozen. Use the feature that matches whether you want headings to stay visible, records to be narrowed down, or values to stand out.

Does the Apps Script example update when a marker is deleted?

Yes, if a user deletes or changes the marker by editing column A, the trigger searches again. If no matching marker remains, the example sets the frozen-row count to zero. It does not react to a marker disappearing solely because a formula recalculated or an external process changed the sheet.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.