Double click to insert character on merged cells

satheo

New Member
Joined
Jun 10, 2014
Messages
34
I have this to allow for double-clicking on a defined group of cells (name manager list: "DoubleClick1") and mark/unmark them with an "X"

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Count > 1 Then Exit Sub
    
    If Not Intersect(Target, Range("DoubleClick1")) Is Nothing Then
        If Target.Value <> "X" Then 
            Target.Value = "X"
            Cancel = True
            Exit Sub
        End If
        If Target.Value = "X" Then 
            Target.ClearContents
            Cancel = True
            Exit Sub
        End If
    End If
End Sub

However I would also like to have this functionality for some merged cells, but not sure how to make that work. Any ideas?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
The following BeforeDoubleClick event replacement for the code you posted will work for regular cells and merged cells...
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  If Not Intersect(Target, Range("DoubleClick1")) Is Nothing Then
    Target.Value = Mid("X", 1 - (Target(1).Value = "X"))
    Cancel = True
  End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,902
Messages
6,122,161
Members
449,069
Latest member
msilva74

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