Double Clicking on A Locked Cell

Jasesair

Board Regular
Joined
Apr 8, 2015
Messages
219
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
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

diddi

Well-known Member
Joined
May 20, 2004
Messages
3,273
Office Version
  1. 2010
Platform
  1. Windows
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
 
Solution

Jasesair

Board Regular
Joined
Apr 8, 2015
Messages
219
Office Version
  1. 2016
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!
 

diddi

Well-known Member
Joined
May 20, 2004
Messages
3,273
Office Version
  1. 2010
Platform
  1. Windows
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.
 

Jasesair

Board Regular
Joined
Apr 8, 2015
Messages
219
Office Version
  1. 2016
Wow, that's quite involved. I think I can live with what I have!!!! Appreciate your efforts.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,653
Messages
5,626,101
Members
416,161
Latest member
David1966Lewis

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