Disable Double Clicking of Locked Cells on Protected Sheets

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,562
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a protected worksheet (being used as a form) in which all the user interactive cells are locked. Only unlocked cells are selectable. I use VBA to unlock them at the appropriate time so the user can enter appropriate information based on the values of previously entered data (often times triggering the unlocking of cells for user entry).

During my worksheet "initialization" - first use - the sheet is protected and only cells C3, E3, G3 and M3 is unlocked for user entry. These cells each have unique list validations. M3 has a 'default' message, which provides only a message for the user, and is not a valid option (not included in the validation list). These 4 cells all have worksheet change event code associated with them.

I also have a range of cells, I13:K19, that have BeforeDoubleClick events associated with them. During initialization, this range is locked as well.

The issue I am having is that if the user double clicks on any cell of the protected worksheet, it triggers the worksheet double click event reserved for range I13:K19, which is locked. Since the cell that the user selected is locked, Excel considers the next unlocked cell as being the cell double clicked. (for example, M3 is unlocked. If the user double clicks Z26, the diagnostic message I coded shows an address of M3. The result is a blinking cursor at the end of the default text in M3. If I click on M3's dropdown button, the cell's validation error message pops up because the default value isn't in the list of available selections. If I press OK, worksheet change code for M3 is triggered and results in errors (as the default value passed is invalid)

How can I disable double clicking of cells except only those I want, when I want?
 
Last edited:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I think I found the solution ... the inclusion of Cancel.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    'MsgBox Target.Address
    If Not Intersect(Target, Range("I13:K19")) Is Nothing Then
         MsgBox "Cell double clicked: " & Target.Address
    Else
        Cancel = True
    End If
End Sub
 
Upvote 0
I think I found the solution ... the inclusion of Cancel.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    'MsgBox Target.Address
    If Not Intersect(Target, Range("I13:K19")) Is Nothing Then
         MsgBox "Cell double clicked: " & Target.Address
    Else
        Cancel = True
    End If
End Sub
Nope ... still doing unpredictable things.
 
Upvote 0
Nope ... still doing unpredictable things.
Turns out that after the double click code executed, I had to send the focus of the cursor somewhere out of site via code. Without this, everytime the user manually left the double clicked selected cell, focus would go to the next unlocked cell and cause a bunch of problems.
 
Upvote 0

Forum statistics

Threads
1,214,414
Messages
6,119,375
Members
448,888
Latest member
Arle8907

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