Hi,
I am using the following macro to cut and paste and then clear contents of a protected sheet but when I try to change it to delete the entire row instead of clearing the contents using "EntireRow.Delete" instead of "ClearContents" I get an error.
I would really appreciate help with this.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect ("")
Dim lrow As Long, lcell As Long
lrow = Sheet2.Cells(Rows.Count, 18).End(xlUp).Row + 1 'next available row on sheet2
lcell = Sheet1.Cells(Rows.Count, 18).End(xlUp).Row 'last cell in column-J on sheet1
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("J2:J" & lcell)) Is Nothing Then
If Target.Value <> vbNullString Then
Range(Cells(Target.Row, 1), Cells(Target.Row, 18)).Copy Destination:=Sheet2.Range("A" & lrow)
Range(Cells(Target.Row, 1), Cells(Target.Row, 18)).ClearContents
End If
End If
ActiveSheet.Protect Password:=""
End Sub
I am using the following macro to cut and paste and then clear contents of a protected sheet but when I try to change it to delete the entire row instead of clearing the contents using "EntireRow.Delete" instead of "ClearContents" I get an error.
I would really appreciate help with this.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect ("")
Dim lrow As Long, lcell As Long
lrow = Sheet2.Cells(Rows.Count, 18).End(xlUp).Row + 1 'next available row on sheet2
lcell = Sheet1.Cells(Rows.Count, 18).End(xlUp).Row 'last cell in column-J on sheet1
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("J2:J" & lcell)) Is Nothing Then
If Target.Value <> vbNullString Then
Range(Cells(Target.Row, 1), Cells(Target.Row, 18)).Copy Destination:=Sheet2.Range("A" & lrow)
Range(Cells(Target.Row, 1), Cells(Target.Row, 18)).ClearContents
End If
End If
ActiveSheet.Protect Password:=""
End Sub