Double Clicking on A Locked Cell

Jasesair

Active Member
Joined
Apr 8, 2015
Messages
282
Office Version
  1. 2016
I'm running some Double Click actions. This works perfectly however if the user double clicks on a locked cell, then the worksheet unprotects itself. This obviously isn't ideal. Any help to solve would be amazing.

This is what I'm running:

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

Dim rng As Range
Cancel = True
Set rng = ActiveSheet.Range("d8:dc77")
Worksheets("2021").Unprotect
If Intersect(Target, rng) Is Nothing Then Exit Sub
Select Case True
    Case Target.Interior.Color = RGB(255, 255, 255): Target.Interior.Color = RGB(198, 239, 206)
    Case Target.Interior.Color = RGB(198, 239, 206): Target.Interior.Color = RGB(255, 199, 206)
    Case Target.Interior.Color = RGB(255, 199, 206): Target.Interior.Color = RGB(255, 255, 255)
End Select
Worksheets("2021").Calculate
Worksheets("2021").Protect
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Dim rng As Range
Cancel = True
Set rng = ActiveSheet.Range("d8:dc77")

If Intersect(Target, rng) Is Nothing Then Exit Sub
Worksheets("2021").Unprotect
Select Case True
    Case Target.Interior.Color = RGB(255, 255, 255): Target.Interior.Color = RGB(198, 239, 206)
    Case Target.Interior.Color = RGB(198, 239, 206): Target.Interior.Color = RGB(255, 199, 206)
    Case Target.Interior.Color = RGB(255, 199, 206): Target.Interior.Color = RGB(255, 255, 255)
End Select
Worksheets("2021").Calculate
Worksheets("2021").Protect
End Sub
 
Upvote 0
Solution
Well, don't I feel like the fool now!!! This has solved the problem but what it now has created is... if I am in a cell within the double click range, then an attempted double click outside the range is actually producing the double click's action in the cursored cell. Hope that makes sense!
 
Upvote 0
i get what you mean. i think you will be forced to use the API to get around this issue because there is no _mousedown event for a worksheet. Jafaar has nailed it in this thread:
it is hard work though.
 
Upvote 0
Wow, that's quite involved. I think I can live with what I have!!!! Appreciate your efforts.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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