VBA & Macro Problems

Prevent Excel VBA Worksheet Change Events During Protected Cell Updates

Elise WilliamsElise Williams Nov 13, 2026 869 views

Question details

Prevent a Worksheet_Change event from interrupting a VBA procedure that updates protected cells.

Prevent Excel VBA Worksheet Change Events During Protected Cell Updates
Product
Microsoft Excel
Device & OS
not provided
Scenario
A VBA procedure unprotects a worksheet, updates several cells, and then protects the sheet again.
Observed behavior
Updating cells triggers Worksheet_Change, which may protect the worksheet again before the procedure has finished.
Before you start

Open the VBA editor with Alt+F11 and identify the worksheet procedure and any Worksheet_Change handler that changes protection. Check the worksheet password and the protection options your workbook requires.

Solution 1Recommended

Disable Excel Events While Updating Protected Cells

Use this approach to prevent event handlers from running during the updates and restore the previous event setting afterward.

Application.EnableEvents applies to the entire Excel application, not just one worksheet. Save its original value and restore it even if the update fails.

The example restores content protection only if the sheet was originally protected. Adapt the Protect arguments to match your workbook's existing permissions and protection options.

1
Open the worksheet module

Press Alt+F11, then select the relevant worksheet under Microsoft Excel Objects in the Project Explorer.

2
Add the update procedure

In the worksheet module, add the procedure below. Replace the password and sample cell updates with your own: Public Sub UpdateProtectedCells() Dim ws As Worksheet Dim eventsWereEnabled As Boolean Dim wasProtected As Boolean Dim pwd As String Dim message As String Set ws = Me pwd = "your-password" eventsWereEnabled = Application.EnableEvents wasProtected = ws.ProtectContents On Error GoTo CleanUp Application.EnableEvents = False If wasProtected Then ws.Unprotect Password:=pwd ws.Range("A1").Value = "First update" ws.Range("A2").Value = "Second update" CleanUp: If Err.Number <> 0 Then message = "Update error: " & Err.Description Err.Clear On Error Resume Next If wasProtected And Not ws.ProtectContents Then ws.Protect Password:=pwd If Err.Number <> 0 Then message = message & vbCrLf & "Protection error: " & Err.Description Err.Clear Application.EnableEvents = eventsWereEnabled If Err.Number <> 0 Then message = message & vbCrLf & "Event restoration error: " & Err.Description On Error GoTo 0 If Len(message) > 0 Then MsgBox message, vbExclamation End Sub

3
Run and verify

Run UpdateProtectedCells from the VBA editor using F5. Confirm that all intended cells were updated, the sheet's protection is correct, and the Worksheet_Change handler still runs for later manual edits if events were enabled originally.

Disable Excel Events While Updating Protected Cells
Match your protection settings: If the original sheet uses specific Protect options, such as permissions for filtering or UserInterfaceOnly, include the appropriate arguments when protecting it again. The example does not preserve those options automatically.
Free Microsoft Office alternative

Work With Excel Spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface. Open compatible Excel files to make the move easier; it does not change Excel's VBA event behavior.

Open and edit compatible Microsoft Excel XLSX and XLS files.Work with protected spreadsheet content using a familiar interface.Use a lightweight office suite with free core editing tools.Move existing spreadsheets into a familiar workspace.
QA img-9

Frequently Asked Questions

Why does changing a cell in VBA run Worksheet_Change?

Excel can fire Worksheet_Change when a worksheet cell is changed by code. Set Application.EnableEvents to False before the updates if the handler must not run, and restore its previous value afterward.

Does Application.EnableEvents affect only the current worksheet?

No. It controls events across the Excel application. Keep the disabled period short and restore the original value in a cleanup section.

What if an error occurs before the worksheet is protected again?

Use On Error GoTo to route failures to a cleanup section. In that section, attempt to restore protection if it was originally enabled, then restore the saved Application.EnableEvents value.

How can I turn events back on if a macro leaves them disabled?

In the VBA editor, open the Immediate window with Ctrl+G, type Application.EnableEvents = True, and press Enter. Do this only if events should be enabled.

Will WPS Office fix the Worksheet_Change event in Excel?

No. The event behavior and Application.EnableEvents setting belong to Excel. WPS Office can open compatible spreadsheet formats, but VBA and macro support can vary by version and environment.