Range(Selection, Selection.End(xlUp)).Select to stop at row 2 and not include header rows.

bensko

Board Regular
Joined
Mar 4, 2008
Messages
173
I'm sure there is a simple solution to this, but I am having trouble finding the right one.

Any way to have Range(Selection, Selection.End(xlUp)).Select stop at row 3 and disregard the two header rows.

Something like Range(Selection, Selection.End(xlUp)-2).Select

Thanks in advance,

Ben
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,836
Office Version
  1. 2019
Platform
  1. Windows
Hi,
I would just stop and check:

Code:
Range(Selection, Selection.End(xlUp)).Select
If Selection.Row < 3 Then
    Cells(3, Selection.Column).Select
End If

ξ
 

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,836
Office Version
  1. 2019
Platform
  1. Windows
Note, or better (to preserve selection size):

Code:
Range(Selection, Selection.End(xlUp)).Select
If Selection.Row < 3 Then
    Selection.Offset(3 - Selection.Row, ).Select
End If

Test first - I may have the syntax wrong.
 

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,836
Office Version
  1. 2019
Platform
  1. Windows
I did have the syntax wrong, and I think we want to resize the selection as well, so, try again:

Code:
Sub foo()

Range(Selection, Selection.End(xlUp)).Select
If Selection.Row < 3 Then
    Selection.Offset(3 - Selection.Row).Resize( _
        Selection.Rows.Count - (3 - Selection.Row), Selection.Columns.Count) _
        .Select
End If


End Sub
 

bensko

Board Regular
Joined
Mar 4, 2008
Messages
173
Sorry for my delayed appreciation - thank you!! This is exactly what I was looking for.

I did have the syntax wrong, and I think we want to resize the selection as well, so, try again:

Code:
Sub foo()

Range(Selection, Selection.End(xlUp)).Select
If Selection.Row < 3 Then
    Selection.Offset(3 - Selection.Row).Resize( _
        Selection.Rows.Count - (3 - Selection.Row), Selection.Columns.Count) _
        .Select
End If


End Sub
 

Forum statistics

Threads
1,171,686
Messages
5,876,892
Members
433,217
Latest member
Muhammad Tanzeel Ur Rehma

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
Top