Selecting a Variable Range by First Row and Last row

alfy_alfy

New Member
Joined
Jun 24, 2016
Messages
2
Hello

I am struggling to select a variable range based on the second row and last row. All I want is to select the entire rows between the variable second row till the last row. And then I want to sort them. I am able to define the last row easy which is quiet straightforward. And I am also able to define the second row easy. Now the issue when i want to select the range between the two (For the entire rows), it doesn't allow me to. Is there a way for this. I have used
Code:
 Range("FirstRow:FinalRow")
. Also I have used
Code:
Rows("Firstrow:Finalrow")
. They both don't work.

So i have provided the simple code i used. Everything is going fine till the last line of the code to be able to select.

Ideally i know if you want to select entire rows for example from row 4 to row 10, you write
Code:
 Rows("4:10").Select
and that works but when it is variable rows that i want to select, I can't seem to do it.

Any help would be really appreciated as I am really struggling with this simple task. Thanks alot.



Code:
 Sub Variablerange()


Dim finalrow As Long
Dim mysheet As Worksheet
Dim myworkbook As Workbook
Dim FirstRow As Long
Dim secondrow As Long


FirstRow = ActiveCell.End(xlUp).Offset(1, 0).Row
Finalrow = mysheet.Cells(Rows.Count, 1).End(xlUp).Row

Rows("Firstrow:lastrow").select

End Sub
 

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).

Forum statistics

Threads
1,215,297
Messages
6,124,107
Members
449,142
Latest member
championbowler

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