Detecting double click

K

kirkm

I'm using the following to launch some VBA when a cell is double
clicked.

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

Dim rng As Range
Dim MyLastRow As String

Set rng
=Worksheets("Sheet1").Range("A1").SpecialCells(xlCellTypeLastCell)
MyLastRow = rng.Row

rows = "J1:J" & MyLastRow

If Not Intersect(Target, Range(rows)) Is Nothing Then
Cancel = True

********* Code here

End If


End Sub
++++++++++

Howver, I'd like to change that so any cell in the range S2 to CD5972
achieves the same result.

Is that possible?
Thanks - Kirk
 
T

Tom Ogilvy

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, Cancel As Boolean)
Dim sAddr as String
sAddr = "S2:CD5972"
If Not Intersect(Target, Range(s)) Is Nothing Then
Cancel = True

********* Code here

End If
End Sub
 
D

Doug Glancy

Kirk,

Excuse me for horning in, but I believe Tom meant the line to be:

If Not Intersect(Target, Range(sAddr)) Is Nothing Then

hth,

Doug
 
G

Guest

Yes I did. Thanks for the correction. That is the second time I have done
that <blush> (this week).
 

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