ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code Question (https://www.excelbanter.com/excel-programming/382794-code-question.html)

kirkm[_6_]

Code Question
 
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(xlC ellTypeLastCell)
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

Jim Cone

Code Question
 
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim rng As Excel.Range
Set rng = Me.Range("S2:CD5972")

If Not Intersect(Target.Cells(1, 1), rng) Is Nothing Then
Cancel = True
'********* Code here
Else
'do something else?
End If
Set rng = Nothing
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"kirkm"
wrote in message
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(xlC ellTypeLastCell)
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


All times are GMT +1. The time now is 08:02 PM.

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