Range of Columns/Rows in DoubleClick

Rocky0201

Active Member
Joined
Aug 20, 2009
Messages
278
Hi,

I'm trying to determine if a cell in a range of cells is double clicked. The columns are B and C and the Rows are 3 to the Last Row. My code looks like this:

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

Dim LR As Long

'-------------------------------------------------------
'Get Data
'-------------------------------------------------------

LR = Sheets("Location Master").Cells(Rows.Count, 1).End(xlUp).Row

If Target.Column = Range("2" & "3") And Target.Row = Range("3" & LR) Then

Sheets("Location Master").Activate
Call ParkAtTop("Location Master")

End If

End Sub

I'm getting a Debug Error in the Target statement when running the code.

Thanks for your help.
 

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).
What's the error type you're seeing?

I'm not encountering any problem with it at all, but I don't have your subs, sheets or named ranges. I just focused on the line that used the Target, created a messagebox, and didn't have any issue.

Maybe try:

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

Dim LR As Long

'-------------------------------------------------------
'Get Data
'-------------------------------------------------------

LR = Sheets("Location Master").Cells(Rows.Count, 1).End(xlUp).Row

If Target.Column = Range("2" & "3")[COLOR=red].Column[/COLOR] And Target.Row = Range("3" & LR)[COLOR=#ff0000].Row [/COLOR]Then

Sheets("Location Master").Activate
Call ParkAtTop("Location Master")

End If

End Sub
 
Upvote 0
I'm sorry but this is just wrong.
Code:
Target.Column = Range("2" & "3") And Target.Row = Range("3" & LR)
If you want to refer to the range you mention you can use this.
Code:
rngCheck = Range("B3:C" & LR)
To see if Target is in that range you can try this.
Code:
If Not Intersect(rngCheck, Target) Is Nothing Then
      ' Target is in the range rngCheck
      ' so do stuff
End If
 
Upvote 0
I figured they were named ranges, Norie.

Edit: Except, that would be Range("2", "3"), wouldn't it.

And even then that wouldn't make sense, because nothing's being done with the ranges. He's just taking the value of each range, and that would have to be compared one at a time.
 
Last edited:
Upvote 0
Thanks Glory.

I still get a debug error on the target statement. Do I need to dim the ranges?

My original statement in my first post was:

If Target.Column = 2 And Target.Row = 1 Then

However, I could double click on any cell in the sheet and the code fell into my Call ParkAtTop("Location Master") routine. BTW - The ParkAtTop routines works fine,

I'm looking to only call the ParkAtTop routine if the double click is in columns b and c and rows 1 to the LR (in my spreadsheet LR is 32 but this value can change).

Thanks again for the help.
 
Upvote 0
Glory

You can't have named ranges with names like '2' and '3'.:)
 
Upvote 0
Just in case you didn't catch it, Norie had your answer.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
 
LR = 32
 
Set theRange = Range("B1:C" & LR)
 
If Not Intersect(Target, theRange) Is Nothing Then
 
MsgBox "Hey"
 
End If
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,056
Messages
6,122,907
Members
449,096
Latest member
dbomb1414

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