Double click a range

R

Robert Crandal

Is there a quick way to detect if the user double
clicks a specified range?

I'm currently dealing with the "Target" parameter of
the Worksheet_BeforeDoubleClick() function. I'm
also testing all the Target.Row and Target.Col
combinations to test for a specified range. Is this
the only way to do this??

Thanks.
 
H

Harald Staff

Hi Robert

You can use named ranges and Intersect for this.
Name a range of cells ClubbingArea and try this:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Dim R As Range
On Error Resume Next
Set R = Intersect(Target(1), Range("ClubbingArea"))
If R Is Nothing Then
Cancel = True
MsgBox "Out"
Else
Cancel = True
MsgBox ("in")
End If
End Sub

HTH. Best wishes Harald
 
W

witek

Robert said:
Is there a quick way to detect if the user double
clicks a specified range?

I'm currently dealing with the "Target" parameter of
the Worksheet_BeforeDoubleClick() function. I'm
also testing all the Target.Row and Target.Col
combinations to test for a specified range. Is this
the only way to do this??

Thanks.


that is the only way


if not intersect (target, <range you are interested in>) is nothing then

.... your code here .....
end if




just be careful with one thing

target can overlap with <your range> but does not have to be fully
included in it.
just decide if in your code you want to play with target or with
intersect (target, <your range>)
 
G

GS

Something like this, perhaps...

If Target.Address <> Range("MySpecificRange").Address Then Exit Sub

OR

If Intersect(Target, Range("MySpecificRange")) Is Nothing Then Exit Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top