ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   double click macros (https://www.excelbanter.com/excel-programming/398140-re-double-click-macros.html)

jack[_2_]

double click macros
 
Here's what doesn't work. How do I correct It so both macros work on
different ranges? The error message I get is: Ambiguous name detected
They both work independently but not on the same project.

Option Explicit

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

Application.EnableEvents = False
On Error GoTo sub_exit
If Not Intersect(Target, Range("c7:c57")) Is Nothing Then
With Target
If .Value = "X" Then
.Value = ""
Else

.Value = "X"

End If
End With
Cancel = True
End If
sub_exit:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Dim Rng1 As Range

'Assign the range to work with
Set Rng1 = Range("D7:D57")

'Only work on assigned range
If Intersect(Target, Rng1) Is Nothing Then Exit Sub

'Cancel cell editing that would normally trigger when you double click
Cancel = True

'Call the userform
UserForm1.Show

End Sub

"jack" wrote in message
...
Can someone help me on how I can set up two different double click macros
(two different resulting actions) on the same worksheet for different
ranges. I have each macro starting with: Private Sub
Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean). I
found very quickly that it doesn't work. What do I need to do so that
each will work independently?
Any basic direction would be appreciated.





Mike

double click macros
 
Try this
Private Sub Worksheet_BeforeDoubleClick _
(ByVal Target As Range, Cancel As Boolean)

If Not Intersect(Target, Range("c7:c57")) Is Nothing Then
With Target
If .Value = "X" Then
.Value = ""
Else
.Value = "X"
End If
End With
Cancel = True
End If
'Assign the range to work with
'Only work on assigned range
If Intersect(Target, Range("D7:D57")) Is Nothing Then Exit Sub

'Cancel cell editing that would normally trigger when you double click
Cancel = True

'Call the userform
UserForm1.Show




End Sub

"jack" wrote:

Here's what doesn't work. How do I correct It so both macros work on
different ranges? The error message I get is: Ambiguous name detected
They both work independently but not on the same project.

Option Explicit

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

Application.EnableEvents = False
On Error GoTo sub_exit
If Not Intersect(Target, Range("c7:c57")) Is Nothing Then
With Target
If .Value = "X" Then
.Value = ""
Else

.Value = "X"

End If
End With
Cancel = True
End If
sub_exit:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Dim Rng1 As Range

'Assign the range to work with
Set Rng1 = Range("D7:D57")

'Only work on assigned range
If Intersect(Target, Rng1) Is Nothing Then Exit Sub

'Cancel cell editing that would normally trigger when you double click
Cancel = True

'Call the userform
UserForm1.Show

End Sub

"jack" wrote in message
...
Can someone help me on how I can set up two different double click macros
(two different resulting actions) on the same worksheet for different
ranges. I have each macro starting with: Private Sub
Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean). I
found very quickly that it doesn't work. What do I need to do so that
each will work independently?
Any basic direction would be appreciated.






jack[_2_]

double click macros
 
Thanks Mike, that worked for me


"Mike" wrote in message
...
Try this
Private Sub Worksheet_BeforeDoubleClick _
(ByVal Target As Range, Cancel As Boolean)

If Not Intersect(Target, Range("c7:c57")) Is Nothing Then
With Target
If .Value = "X" Then
.Value = ""
Else
.Value = "X"
End If
End With
Cancel = True
End If
'Assign the range to work with
'Only work on assigned range
If Intersect(Target, Range("D7:D57")) Is Nothing Then Exit Sub

'Cancel cell editing that would normally trigger when you double click
Cancel = True

'Call the userform
UserForm1.Show




End Sub

"jack" wrote:

Here's what doesn't work. How do I correct It so both macros work on
different ranges? The error message I get is: Ambiguous name detected
They both work independently but not on the same project.

Option Explicit

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

Application.EnableEvents = False
On Error GoTo sub_exit
If Not Intersect(Target, Range("c7:c57")) Is Nothing Then
With Target
If .Value = "X" Then
.Value = ""
Else

.Value = "X"

End If
End With
Cancel = True
End If
sub_exit:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Dim Rng1 As Range

'Assign the range to work with
Set Rng1 = Range("D7:D57")

'Only work on assigned range
If Intersect(Target, Rng1) Is Nothing Then Exit Sub

'Cancel cell editing that would normally trigger when you double
click
Cancel = True

'Call the userform
UserForm1.Show

End Sub

"jack" wrote in message
...
Can someone help me on how I can set up two different double click
macros
(two different resulting actions) on the same worksheet for different
ranges. I have each macro starting with: Private Sub
Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean).
I
found very quickly that it doesn't work. What do I need to do so that
each will work independently?
Any basic direction would be appreciated.









All times are GMT +1. The time now is 03:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com