A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi!
Welcome to Microsoft Q&A forum.
You can do it by temporarily unprotecting the sheet (and the destination sheet, if protected) inside your Worksheet_Change event,and reprotecting them immediately afterward. If this is possible to your work you can study sample below.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Dim rng As Range
Dim lastRow As Long
Dim pw As String
' Your worksheet password (if any)
pw = "yourpassword" ' Change this to your actual password, or leave blank if none
On Error GoTo SafeExit
Application.EnableEvents = False
' Only react to changes in column Z (column 26)
If Not Intersect(Target, Me.Columns(26)) Is Nothing Then
' Unprotect current sheet
Me.Unprotect Password:=pw
' Get the destination sheet
Set ws = Worksheets(Target.Value)
' Unprotect destination sheet if it’s protected
ws.Unprotect Password:=pw
' Find the next available row in the destination sheet
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1
' Copy the row from the Register sheet
Set rng = Me.Range("A" & Target.Row & ":D" & Target.Row)
rng.Copy ws.Range("A" & lastRow)
' Delete the original row
rng.Delete Shift:=xlUp
' Reprotect both sheets
Me.Protect Password:=pw
ws.Protect Password:=pw
End If
SafeExit:
Application.EnableEvents = True
End Sub
Note:
- Replace "yourpassword" with your actual sheet password, or leave it blank ("") if no password.
- The macro disables events (Application.EnableEvents = False) to prevent recursive triggering.
- Both the source sheet and destination sheet are unprotected before modification and then protected again.
- The SafeExit label ensures that events are re-enabled even if an error occurs.