Data Protection. How to Lock a Row in Google Sheets

How to Lock a Row in Google Sheets #

Google Sheets is a powerful tool for organizing and analyzing data, but it's important to maintain data integrity and prevent unintended changes. One way to achieve this is by locking a row, which allows you to protect specific rows of data from being edited or deleted. In this article, we will explore how to lock a row in Google Sheets, manually and through a Google Apps script. We will also discuss some practical use cases for locking rows.

Manually Locking a Row #

To manually lock a row in Google Sheets, follow these steps:

  1. Open the Google Sheets document where you want to lock a row.

  2. Select the row you want to lock by clicking on the row number on the left side of the sheet. You can select multiple rows by holding down the "Ctrl" key (Windows) or the "Command" key (Mac) while clicking.

  3. From the top menu, click on "Data" > "Protect sheets and ranges."

  4. In the sidebar that appears on the right side of the sheet, click on "Set Permissions."

  5. Under the "Permissions" tab, choose the options that suit your requirements. You can select "Only myself" to prevent others from editing the locked row or choose specific users or groups.

  6. Optionally, you can set restrictions on certain actions, such as preventing users from deleting or inserting rows.

  7. Once you've configured the permissions, click on the "Set Permissions" button to apply the changes.

Using a Google Apps Script to Lock a Row #

If you frequently need to apply the same row locking settings across multiple sheets or documents, you can use a Google Apps Script to automate the process. The following script locks a row in a specific sheet:

function lockRow() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var rowToLock = 3; // Change this to the desired row number.

var protections = sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (var i = 0; i < protections.length; i++) {
var protection = protections[i];
var range = protection.getRange();
if (range.getRow() == rowToLock) {

var rangeToLock = sheet.getRange(rowToLock, 1, 1, sheet.getLastColumn());
var newProtection = rangeToLock.protect();
newProtection.setDescription("Locked Row");

To use this script, follow these steps:

  1. Open the Google Sheets document where you want to lock a row.

  2. Click on "Extensions" > "Apps Script".

  3. Replace the default code with the provided script.

  4. Edit the rowToLock variable to specify the row number you want to lock.

  5. Save the script.

  6. Click on the play button icon or use the keyboard shortcut "Ctrl + Enter" (Windows) or "Command + Enter" (Mac) to run the script.

  7. Grant the necessary permissions when prompted.

Use Cases for Locking Rows #

  1. Financial documents: Locking a row containing financial information ensures that important figures remain unaltered and accurately represent the data.

  2. Team collaboration: If teams are working on different sections of a spreadsheet, locking relevant rows prevents accidental changes and ensures each team member can focus on their designated data.

  3. Templates or forms: When using spreadsheet templates or forms, locking specific rows can maintain the structure and integrity of the template or form.

  4. Reports or summaries: If you have summary rows that you update based on other data, locking them prevents unintentional changes and ensures the correct information is displayed.

In conclusion, locking a row in Google Sheets is an effective way to safeguard your data and prevent unintended modifications. Whether you choose to manually lock rows or utilize a Google Apps script for automation, the ability to protect rows provides added security and data integrity to your spreadsheets.

To link to another sheet in Google Sheets, you can use the formula "=HYPERLINK("URL","link label")".

To lock a row in Google Sheets and prevent it from being modified, check out for step-by-step instructions on securing specific rows.

When you want to link cells within a Google Sheets document, take a look at to learn how to create clickable references between cells.

To lock cells from editing in Google Sheets, you can utilize the Protect sheets and ranges feature to ensure the security of sensitive data.