Doubleclick event does not work on unprotected cell when sheet is protected

David1028

New Member
Joined
Feb 15, 2016
Messages
19
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Cancel = True

ActiveCell.Value = ActiveCell.Offset(-1, 0)


End Sub

Why will the above code not work when I protect a worksheet? The cells i want to be able to doubleclick and copy above information are not locked?
Is there a workaround?

Thanks
 

Some videos you may like

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

dave3009

Well-known Member
Joined
Jun 23, 2006
Messages
7,002
Office Version
  1. 365
  2. 2016
Hi David1028

What error do you get when double clicking the cells. This copies the cell from above so let's say A1 is unlocked and you want to copy it to B1...So is B1 unlocked?

Thanks

Dave
 

David1028

New Member
Joined
Feb 15, 2016
Messages
19
Thanks for replying Dave, yes both cells are unlocked. I do not get an error message, the doubleclick just does not work. And yes there is data in the above cell.

Thank you again
 

dave3009

Well-known Member
Joined
Jun 23, 2006
Messages
7,002
Office Version
  1. 365
  2. 2016
Where to you have the code placed David? Is it a sheet module, thisworkbook module or standard module?
 

David1028

New Member
Joined
Feb 15, 2016
Messages
19

ADVERTISEMENT

Presently lies in workbook module, but I have tried it in the sheet module and same issue occurs
 

dave3009

Well-known Member
Joined
Jun 23, 2006
Messages
7,002
Office Version
  1. 365
  2. 2016
So in ThisWorkbook? OK

In the VBE open the immediate window by pressing Ctrl+G then paste this in. Then hit Enter.

Code:
Application.EnableEvents = true

Go back to your sheet. Does this change the behaviour of the double click event?
 
Last edited:

David1028

New Member
Joined
Feb 15, 2016
Messages
19

ADVERTISEMENT

Sorry, had to attend a meeting...
But no adding that code in the immediate window did not change anything
 

jeffreybrown

Well-known Member
Joined
Jul 28, 2004
Messages
5,145
Hi David,

Dave may not be back tonight as it is close to midnight for him.

Try this

Right click on the sheet you want this to run >> View code

Unlock the cell you are going to Double click on

Protect the sheet

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Cancel = True
    ActiveCell.Value = ActiveCell.Offset(-1, 0)
End Sub

1) Are you trying to do this for a worksheet or workbook?
2) Macros are enabled, correct?
 

David1028

New Member
Joined
Feb 15, 2016
Messages
19
Found the answer .... needed to allow for edit object when protecting the sheet
 

jeffreybrown

Well-known Member
Joined
Jul 28, 2004
Messages
5,145
Found the answer .... needed to allow for edit object when protecting the sheet

If that works for you then great; however, I don't have to select edit object when protecting the sheet and it still works.

Anyway, glad you found your solution.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,494
Messages
5,602,004
Members
414,490
Latest member
Rip181

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
Top