VBA Excel. Delete time stamp in protected cells using event code.

Jmuniz_Vargas

New Member
Joined
May 21, 2013
Messages
6
Good morning to all,

I wish to delete values in editable rows in a protected excel sheet. I have the following code event
Private Sub Worksheet_Change(ByVal Target As Range)

ActiveSheet.Unprotect Password:="avalon"
If Target.Column = 2 Then
Application.EnableEvents = False
Cells(Target.Row, 5).Value = Date + Time
Application.EnableEvents = True
End If
ActiveSheet.Protect Password:="avalon"
End Sub

The idea is when I delete data in editable rows located in column 'B' at the same time, in column 'E'(where is located an stamp time and, also, they are protected) to delete the related cell to clean up the data from those columns ('B'and 'E'). I hope to be clear, if not let me know to try to clarify my need to discover the proper code based on events.

Thanks in advance.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect Password:="avalon"
    If Target.Column = 2 Then
    Application.EnableEvents = False
        If Len(Target.Value) = 0 Then
            Range("E" & Target.Row).Value = ""
        Else
            Cells(Target.Row, 5).Value = Date + Time
        End If
    Application.EnableEvents = True
    End If
ActiveSheet.Protect Password:="avalon"
End Sub
 
Upvote 0
Try this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect Password:="avalon"
If Target.Column = 2 Then
Application.EnableEvents = False
If Target.Value = "" Then
Target.Offset(0, 3).Value = ""
Else
Target.Offset(0, 3).Value = Date + Time
End If
Application.EnableEvents = True
End If
ActiveSheet.Protect Password:="avalon"
End Sub
 
Upvote 0
As a side note:
You do not need to use:

Code:
Target.Offset(0, 3).Value = Date + Time
You could use

Code:
Target.Offset(0, 3).Value = Now
 
Upvote 0
Try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect Password:="avalon"
    If Target.Column = 2 Then
    Application.EnableEvents = False
        If Len(Target.Value) = 0 Then
            Range("E" & Target.Row).Value = ""
        Else
            Cells(Target.Row, 5).Value = Date + Time
        End If
    Application.EnableEvents = True
    End If
ActiveSheet.Protect Password:="avalon"
End Sub


Thank you very much. It is working perfectly! :)
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,835
Messages
6,121,880
Members
449,057
Latest member
Moo4247

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top