VBA - If Target Not Intersect Till Last Row

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,516
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I am using the range A4:A100 since I do not know how to change it to look from A4 till the last row.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)   
  
 If Not Intersect(Target, Range("[B][COLOR=#ff0000]A4:A100[/COLOR][/B]")) Is Nothing Then
   
 Call Macro1
   
End If
    
End Sub


If anyone friend can provide a solution.

Thanks in advance

Regards,

Humayun
 
Last edited:

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).
One way:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)   
  
 Dim lr as Long

 lr = Cells(Rows.Count, "A").End(xlUp).Row

 If Not Intersect(Target, Range("[B][COLOR=#ff0000]A4:A" & lr[/COLOR][/B])) Is Nothing Then
      Call Macro1
 End If
    
End Sub
 
Upvote 0
How about
Code:
 If Not Intersect(Target, Range("[B]A4:A[/B]"&Rows.Count)) Is Nothing Then
 
Upvote 0
Thanks Fluff,

Tried your code too... Its looking beyond the last row.
 
Upvote 0
Thanks Fluff,

Tried your code too... Its looking beyond the last row.
Mine actually looks to the lastrow as specified, Joe's looks to the last used row ;)
 
Upvote 0
Mine actually looks to the lastrow as specified, Joe's looks to the last used row
Just to clarify, that returns the last possible row on the entire sheet (row 1048576 on xlsx files).

As Fluff said, mine chooses the last used row in column A (so it stops there).
 
Upvote 0
Thanks.... Got it:)

I realised that in my first post I did not write that I want last used row.... instead I wrote last row.
I should have written last used row
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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