Skip to main content

How to insert or delete rows in protected sheet? 

Author Xiaoyang Last modified

When working with sensitive or shared data in an Excel worksheet, protecting the sheet is a commonly used method to avoid accidental or unauthorized changes. However, by design, sheet protection also restricts certain operations, such as inserting or deleting rows, especially in cells that are locked. Many users often encounter the problem where they need to allow editing, like inserting or deleting rows, while still keeping the rest of the worksheet protected. This tutorial illustrates practical ways to insert or delete rows on a protected sheet and discusses their application scenarios, precautions, and alternative solutions to help you manage your data securely and efficiently.

Insert or delete rows in protected sheet

VBA: Temporarily unprotect, insert/delete, and reprotect automatically


Insert or delete rows in protected sheet

This solution is best suited for situations where you want users to have limited editing rights, such as inserting or deleting rows, while keeping the majority of your worksheet protected. It allows specified rows or sections of data to remain flexible and editable, while the rest of the sheet is secured from accidental changes or deletions.

Follow these step-by-step instructions to enable row insertion and deletion in a protected sheet:

1. Select the entire rows that you want users to be able to insert or delete. This process determines where in your protected worksheet these operations will be allowed. After selecting the rows, right-click on the selection, then choose Format Cells from the context menu. See screenshot:

a screenshot of selecting Format Cells after right-clicking on the selected rows

2. In the appearing Format Cells dialog, navigate to the Protection tab. Here, uncheck the Locked box to unlock these specific cells or rows. Unlocking is essential; otherwise, users still won't be able to make changes even with other permissions. Be cautious not to unlock sensitive areas you want to remain protected. See screenshot:

a screenshot of unchecking the Locked option in the Format Cells dialog box

3. Click OK to close the dialog box. Next, go to the Excel ribbon, click Review and then select Protect Sheet to enable worksheet protection. See screenshot:

a screenshot of enabling the Protect Sheet feature

4. In the Protect Sheet dialog that appears, you will see a list labeled Allow all users of this worksheet to. Check the Insert rows and Delete rows options. Enter a password to protect the sheet, if needed, and confirm it when prompted. This step is crucial for granting only the desired editing permissions to users while securing the rest of the sheet. See screenshot:

a screenshot of the Protect Sheet dialog box with password specified and Insert Row and Delete Row options checked

5. Finally, click OK to enable sheet protection under the new settings. As a result, only the specified rows can now be inserted or deleted, according to the permissions and unlocks you configured, while the rest of the worksheet remains unaffected. See screenshot:

a screenshot of rows that can be deleted and inserted in a protected worksheet

This method works well for most basic needs but note that it does not allow users to insert or delete rows outside of the unlocked, permission-granted areas. Always review which cells are unlocked before enabling protection to avoid unintentional data exposure or inadequate protection.

If you need to allow insertion or deletion throughout wider sheet regions, or want more automation, consider VBA-based solutions below.


VBA: Temporarily unprotect, insert/delete, and reprotect automatically

This VBA macro approach is ideal for users who need to insert or delete rows frequently in a protected worksheet without manually unlocking and relocking the sheet each time. By running a macro, you can temporarily unprotect the sheet, perform row manipulations, and then have the sheet automatically protected again—all at the click of a button. This is especially suitable for collaborative or recurring tasks, ensuring data is both flexible and continually secured.

Main advantages of this approach include minimizing accidental exposure of sensitive data by limiting the unprotected window, and avoiding the hassle of repeatedly entering passwords for routine editing. However, a potential limitation is the need to have macros enabled, and basic macro security understanding is required.

1. Open the worksheet where you want to enable this functionality. Click the Developer tab (if the Developer tab is not visible, you can enable it via File > Options > Customize Ribbon), and then click Visual Basic. In the VBA editor window that appears, select Insert > Module, and paste the following code into the module:

Sub InsertRowInProtectedSheet()
    Dim ws As Worksheet
    Dim pwd As String
    Set ws = ActiveSheet
    pwd = InputBox("Enter sheet password:", "KutoolsforExcel")
    
    If pwd = "" Then Exit Sub
    
    On Error Resume Next
    ws.Unprotect Password:=pwd
    
    If Err.Number <> 0 Then
        MsgBox "Incorrect password or unprotect failed!", vbExclamation
        Exit Sub
    End If
    
    On Error GoTo 0
    Dim insertRow As Integer
    insertRow = Application.InputBox("Enter row number to insert:", "KutoolsforExcel", Type:=1)
    
    If insertRow > 0 Then
        ws.Rows(insertRow).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        MsgBox "Row inserted at " & insertRow, vbInformation
    End If
    
    ws.Protect Password:=pwd, AllowInsertingRows:=True, AllowDeletingRows:=True
End Sub

Sub DeleteRowInProtectedSheet()
    Dim ws As Worksheet
    Dim pwd As String
    Set ws = ActiveSheet
    pwd = InputBox("Enter sheet password:", "KutoolsforExcel")
    
    If pwd = "" Then Exit Sub
    
    On Error Resume Next
    ws.Unprotect Password:=pwd
    
    If Err.Number <> 0 Then
        MsgBox "Incorrect password or unprotect failed!", vbExclamation
        Exit Sub
    End If
    
    On Error GoTo 0
    Dim delRow As Integer
    delRow = Application.InputBox("Enter row number to delete:", "KutoolsforExcel", Type:=1)
    
    If delRow > 0 Then
        ws.Rows(delRow).Delete
        MsgBox "Row " & delRow & " deleted.", vbInformation
    End If
    
    ws.Protect Password:=pwd, AllowInsertingRows:=True, AllowDeletingRows:=True
End Sub

2. Close the VBA editor. To insert a row, press Alt + F8 to open the Macro dialog, select InsertRowInProtectedSheet, and click Run; to delete a row, select DeleteRowInProtectedSheet and click Run. You will be prompted to enter the worksheet password and specify which row to insert or delete. This method reprotects the sheet immediately after the operation to ensure continuous security. Be sure to save your workbook as a macro-enabled file (.xlsm) for future use.

Tips:

  • Always confirm you have the correct password before running the macro, as an incorrect password will block the automation.
  • If any error occurs, review input values and ensure macros are enabled in your Excel Trust Center settings.

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!