BeforeDoubleClick on Protected Sheet with DataValidation

Teun Ham

Board Regular
Joined
Mar 1, 2005
Messages
88
I have a protected sheet where users can make choices (by DataValidation) to certain cells.

I want to use the "BeforeDoubleClick" event to let the users switch between the options.
So if a cell holds "Option A" and "Option B", then doubleclicking would switch from "Option A" to "Option B" and vice-versa.

But the "BeforeDoubleClick" is never fired when a cell has DataValidation applied to it (when the sheet is protected)

Does anyone have a workaround for this issue?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim sCheckRange As Variant
    sCheckRange = Array("NamedCell1", "NamedCell2")
    Dim i As Integer
    For i = LBound(sCheckRange) To UBound(sCheckRange)
        If Not Intersect(Target, ThisWorkbook.Names(sCheckRange(i)).RefersToRange) Is Nothing Then
            Dim sOptions As Variant
            sOptions = Split(ThisWorkbook.Names(sCheckRange(i)).RefersToRange.Validation.Formula1, ";")
            
            Dim iOptionIndex As Integer
            
            Dim j As Integer
            For j = LBound(sOptions) To UBound(sOptions)
                If ThisWorkbook.Names(sCheckRange(i)).RefersToRange.Value = sOptions(j) Then
                    iOptionIndex = j
                    Exit For
                End If
            Next j
            
            If iOptionIndex = UBound(sOptions) Then
                'Active option is the last option of the list, so select the first option
                ThisWorkbook.Names(sCheckRange(i)).RefersToRange.Value = sOptions(0)
            Else
                'Select the next option
                ThisWorkbook.Names(sCheckRange(i)).RefersToRange.Value = sOptions(iOptionIndex + 1)
            End If
            
            Cancel = True
        End If
    Next i
End Sub

This is the code I am using. If you want, you can test it yourself, you only have to change the array called "sCheckRange" to inculde the NamedRanges which have DataValidation (List).

The code works if the sheet is unprotected, but when the sheet is protected the BeforeDoubleClick is not fired when doubleclicking on the cell.

The BeforeDoubleClick IS fired when you doubleclick on a protected cell. So if I first select the cell with the DataValidation and then doubleclick on an protected cell, the BeforeDoubleClick is being fired. As the protected cell does not change the Target, the "current" cell is used instead.

But this behaviour is counter-intuitive (select the cell you want to change, then doubleclick somewhere else to change the cell you want to change)

So, in the end, I am still looking for a solution which solves the "BeforeDoubleClick on a cell with DataValidation on a Protected Sheet"-event notbeing fired.
 
Upvote 0
I have searched some more, but can't find any post/blog/etc. with a solution... :-(

Anyone?
 
Last edited:
Upvote 0
Do you necessarly have to do this by rightclicking the worksheet ? why don't you use a Button next to the cell with validation and perform whatever you want by clicikng on the button ? That should also be more user-freindly.
 
Upvote 0
Genious! I was so focused on the DoubleClick that I forgot that there's also a RightClick event!

DoubleClicking with Validation does not work on a protected sheet, but RightClick does! (just tested this)

Thanks Jaafar!
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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