Kevin0427

Board Regular
Joined
Mar 31, 2016
Messages
69
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)



'Plan Rejected
If Target.Column = 12 Then
ActiveSheet.Unprotect Password:="test"
Target.Offset(0, -6) = 0
'Target.Offset(0, 1) = Date + Time
Target = "þ"
'Range("b" & Target.Row & ":bz" & Target.Row).Locked = True
ActiveSheet.Protect Password:="test"
End If

I am confused by the following code. The two rows that you see as commented out do not run when they are uncommented. If I switch the two target.offset codes the first one always runs and the second one does not. The locked range used to work until I added the second offset and now it does not run even if bad code gets commented out.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Kevin, be more specific and use... Target.Value = "þ" and that should hopefully do it.
 
Upvote 0
You're code works perfectly well for me.
Do you have any other Event code working on that sheet?
 
Upvote 0
In that case try
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Plan Rejected
   If Target.Column = 12 Then
      Cancel = True
      Application.EnableEvents = False
      ActiveSheet.Unprotect Password:="test"
      Target.Offset(0, -6) = 0
      Target.Offset(0, 1) = Date + Time
      Target = "þ"
      Range("b" & Target.Row & ":bz" & Target.Row).Locked = True
      ActiveSheet.Protect Password:="test"
   End If
   Application.EnableEvents = True
End Sub
 
Upvote 0
try this update

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)


    On Error GoTo exitsub
    Me.Unprotect Password:="test"
    
'Plan Rejected
    With Target
        If .Column = 12 Then
        Application.EnableEvents = False
        Cancel = True
            .Offset(0, -6).Value = 0
            .Offset(0, 1).Value = Now()
            .Value = "þ"
        End If
    End With
    Me.Range("b" & Target.Row).Resize(, 77).Locked = True
    
exitsub:
    Me.Protect Password:="test"
    Application.EnableEvents = True
End Sub

Dave
 
Last edited:
Upvote 0
In that case try
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Plan Rejected
   If Target.Column = 12 Then
      Cancel = True
      Application.EnableEvents = False
      ActiveSheet.Unprotect Password:="test"
      Target.Offset(0, -6) = 0
      Target.Offset(0, 1) = Date + Time
      Target = "þ"
      Range("b" & Target.Row & ":bz" & Target.Row).Locked = True
      ActiveSheet.Protect Password:="test"
   End If
   Application.EnableEvents = True
End Sub

I meant to quote this. It worked. Why do I not need it in the rest of the event codes?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,486
Messages
6,113,932
Members
448,533
Latest member
thietbibeboiwasaco

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