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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

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,137,298
Messages
5,680,695
Members
419,927
Latest member
Axtros

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