Double Clicking on A Locked Cell

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
With the exception of a couple ranges of a worksheet, that worksheet's cell are locked and the sheet protected.
I have noticed though, is that if a user double clicks on a locked cell, Excel seems to assume the user has double clicked on the closest unlocked cell. My unlocked cells have doubleclick actions associated to them, so when Excel executes an indirectly double clicked cell (ie user doubleclicks a locked cell), all hell breaks loose. Code is being run when it shouldn't.

How can I avoid this happening?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
After you lock cells, you need to "Protect" the workbook/worksheet in order for it to take affect.
When you do this, it gives you a bunch of options on what you can allow users to do.
Make sure that the "Select unlocked cells" option is checked (by default, usually just the top 2 options are checked).
That will allow them to double-click and select the cell, though they won't be able to do anything with it.
 
Upvote 0
Hi Joe, thank you for your help. I already have "Select unlocked cells" checked and I'm having this behaviour. "Select locked cells" is unchecked.
 
Upvote 0
You will need to limit the code to only work on certain ranges.
 
Upvote 0
I cannot reproduce your behavior. Whenever I double-click on a locked protected cell, it selects that cell, but then gives me an error message saying:
"The cell or chart you're trying to change is on a protected sheet. To make a change, unprotect the sheet. You might be requested to enter a password."
 
Upvote 0
If "Select locked cells" is unchecked & I run this
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
MsgBox Target.Address
Cancel = True
End Sub
It gives the address of the selected cell, not the cell that was clicked.
 
Upvote 0
I think I have done that ...

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Stop
    Dim rng_permit As Range, rng_cdata As Range, rng_sname As Range, rng_sstart As Range, rng_send As Range
    
    With ws_gui1
        If page = 2 Then 'executes only with a date specified page, not the ActiveNet Page
            'MsgBox Target.Address
            'MsgBox Target.Row
            'MsgBox Target.Column
'
            Set tgt = Target
            'Debug.Print tgt
            tgt_r = Target.Row
            tgt_c = Target.Column
            Set rng_permit = .Range("C6:C" & .Cells(.Rows.Count, "C").End(xlUp).Row)
            Set rng_cdata = .Range("AP4:AP" & .Cells(.Rows.Count, "AP").End(xlUp).Row)
            Set rng_sname = .Range("BA4:BA" & .Cells(.Rows.Count, "BA").End(xlUp).Row)
            Set rng_sstart = .Range("BD4:BD" & .Cells(.Rows.Count, "BD").End(xlUp).Row)
            Set rng_send = .Range("BE4:BE" & .Cells(.Rows.Count, "BE").End(xlUp).Row)
            Set rng_asgmt = .Range("AM4:AM" & .Cells(.Rows.Count, "AM").End(xlUp).Row)
            
            If Not Intersect(Target, rng_permit) Is Nothing Then 'doubleclick in permit range
                MsgBox "Permit range - Row: " & tgt_r
                sel_permit
            ElseIf Not Intersect(Target, rng_cdata) Is Nothing Then 'doubleclick in coredata stats range
                MsgBox "Core Data - Row: " & tgt_r
                sel_coredata
            ElseIf Not Intersect(Target, rng_sname) Is Nothing Then 'doubleclick in staff name
                MsgBox "Staff Name - Row: " & tgt_r
                Stop
            ElseIf Not Intersect(Target, rng_sstart) Is Nothing Then 'doubleclick in staff start
                MsgBox "Staff Start - Row: " & tgt_r
                Stop
            ElseIf Not Intersect(Target, rng_asgmt) Is Nothing Then 'doubleclick in assignment
                MsgBox "Assignment - Row: " & tgt_r
                Stop
            Else 'Intersect(tgt, rng_send) Then
                MsgBox "Staff End - Row: " & tgt_r
                Stop
            End If
        Else
            MsgBox "Nothing to see here."
        End If
    End With
End Sub

Normally the cells in these ranges are locked, and then become accessible in the code associated with that selection.

So, what I am experiencing is rng_asgmt is locked. rng_sstart is unlocked. When a user double clicks a cell in rng_asgmt it triggers the code associated to a double click in the rng_sstart. In fact, if I click on any protected cell on the worksheet, it always jumps to a cell in rng_sstart.

I'm wondering if when the worksheet becomes active, it goes to the first available unlocked cell and as that cell is selected by default, that is the one that the interest target is picking up on.
 
Upvote 0
Hi Fluff, yes ... adding "Cancel = True" did correct this behaviour. I don't understand it, but it works!

Thank you all for your gesture of support.
 
Upvote 0
Glad it's sorted & thanks for the feedback
 
Upvote 0
Oh no Fluff. Now no double clicks are being picked up. Even in unlocked ranges I am getting "Nothing to see here" (with reference to my code above).
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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