Saltar al contenido
Microsoft Office

Protect Existing Data in Excel While Still Allowing New Entries

Unlock the entry range, protect the sheet with a password, and add a Worksheet_Change macro that locks each cell as soon as data is entered.

Probado en Excel 2019, Excel for Microsoft 365

For logs, registers and shared trackers you often want an “append-only” sheet: anyone can add a new entry, but nobody can quietly change or delete earlier ones. Excel can do this with sheet protection plus a short macro that locks each cell once it has been filled in.

Step 1 – Unlock the entry area

  1. Select the range people will type into (for example A2:M2000).
  2. Press Ctrl + 1 to open Format Cells.
  3. On the Protection tab, clear Locked and click OK.

Step 2 – Protect the sheet

  1. Go to Review → Protect Sheet.
  2. Enter a password, keep “Select unlocked cells” ticked, and confirm the password.

Step 3 – Add the macro

Right-click the sheet tab and choose View Code. Paste the code below into the sheet’s code window, changing the range and the password to match yours:

Sheet code (VBA)
Private Sub Worksheet_Change(ByVal Target As Range)n    Dim entered As Rangen    On Error GoTo Donen    Set entered = Intersect(Me.Range(u0022A2:M2000u0022), Target)n    If entered Is Nothing Then Exit Subn    Me.Unprotect Password:=u0022YourPasswordu0022n    entered.Locked = Truen    Me.Protect Password:=u0022YourPasswordu0022nDone:nEnd Sub

Step 4 – Save and test

  1. Save the workbook as Excel Macro-Enabled Workbook (.xlsm) – a normal .xlsx drops the macro.
  2. Type into an empty cell in the range: it accepts the value and then locks.
  3. Try to edit or clear that cell – Excel refuses because the sheet is protected.

Limits of this approach

Sheet passwords stop accidental changes, not a determined user – the password is visible in the VBA code unless you also lock the VBA project (Tools → VBAProject Properties → Protection). Macros must be enabled. For audit-grade records, use a database or SharePoint list with version history.

To correct a mistake later, unprotect the sheet with your password (Review → Unprotect Sheet), fix the cell and protect the sheet again.

Inder Kochar

Escrito por

Inder Kochar

Ingeniero de sistemas y redes – Documento las soluciones que aplico con mis clientes, probadas en sistemas reales. ¿Atascado con algo parecido?

Seguir leyendo

Haga una pregunta o comparta su solución

Su correo no se publica. Los comentarios se moderan – por favor, cíñase al tema.