Double Click Ambiguous Error

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
826
Office Version
  1. 365
Platform
  1. Windows
I am unsure how to combined the 2 macros below so I want get a error. Thanks for the Help

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


 Dim isect As Object


 'Test if target in required range
 Set isect = Application.Intersect(Target, Range("M5:P34"))


 If Not isect Is Nothing Then
 'Cancel Edit mode invoked by double click
 Cancel = True


 'Test if cell already contains check mark
 If ActiveCell = Chr(252) Then
 'Clear check mark
 ActiveCell.ClearContents
 Else
 'Insert check mark code
 ActiveCell = Chr(252)
 'Change font to Wingdings
 With ActiveCell.Characters _
 (Start:=1, Length:=1).Font


 .Name = "Wingdings"


 End With
 End If
 End If


 End Sub


Private Sub Worksheet_BeforeDoubleClick( _
            ByVal Target As Range, Cancel As Boolean)
    Dim rInt As Range
    Dim rCell As Range


    Set rInt = Intersect(Target, Range("L5:L34"))
    If Not rInt Is Nothing Then
        For Each rCell In rInt
            rCell.Value = "FCM"
        Next
    End If
    Set rInt = Nothing
    Set rCell = Nothing
    Cancel = True
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try this
Code:
Private Sub Worksheet_BeforeDoubleClick _
 (ByVal Target As Range, Cancel As Boolean)
Dim isect As Object
Dim rInt As Range
Dim rCell As Range

    'Test if target in required range
    Set isect = Application.Intersect(Target, Range("M5:P34"))


    If Not isect Is Nothing Then
        'Cancel Edit mode invoked by double click
        Cancel = True

        'Test if cell already contains check mark
        If Target.Value = Chr(252) Then
            'Clear check mark
            Target.ClearContents
        Else
            'Insert check mark code
            Target.Value = Chr(252)
            'Change font to Wingdings
           Target.Font.Name = "Wingdings"
        End If
    End If

    Set rInt = Intersect(Target, Range("L5:L34"))

    If Not rInt Is Nothing Then
        Cancel = True
        For Each rCell In rInt
            rCell.Value = "FCM"
        Next
    End If
    Set rInt = Nothing
    Set rCell = Nothing
    
End Sub
 
Upvote 0
You could test the cell clicked this way

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

    If Not Intersect(Target, Range("M5:P34")) Then
        ' code for checkmark
        Cancel = True
    ElseIf Not Intersect(Target, Range("L5:L34") Then
        ' code for PCM
        Cancel = True
    End If
End Sub

BTW, the loop for the PCM is not needed, since one cannot DoubleClick on more than one cell at a time.
 
Upvote 0

Forum statistics

Threads
1,216,106
Messages
6,128,863
Members
449,475
Latest member
Parik11

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