Selection of rows (variable)

cmazur71

Board Regular
Joined
Aug 7, 2003
Messages
63
I want to select a group of rows, depending on how many are in my spreadsheet
I set 'a' to equal the number of rows...now I need to select rows 2 thru a, but I cannot figure out the formatting. How do I do this?

a = Worksheets("Final").Cells(Rows.Count, 1).End(xlUp).Row
Rows("2:" & a).Select
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
How about
VBA Code:
Dim a As Long
Worksheets("Final").Select
a = Cells(Rows.Count, 1).End(xlUp).Row
Rows("2:" & a).Select
 
Upvote 0
Solution
How about
VBA Code:
Dim a As Long
Worksheets("Final").Select
a = Cells(Rows.Count, 1).End(xlUp).Row
Rows("2:" & a).Select
I'm getting an error when i get to the Rows command: Run Time Error 1004 Select Method of Range class failed:

Dim endrow As Long
Worksheets("Final").Range("A1").Select
endrow = Cells(Rows.Count, 1).End(xlUp).Row
Rows("2:" & endrow).Select
 
Upvote 0
This line
VBA Code:
Worksheets("Final").Range("A1").Select
should be
VBA Code:
Worksheets("Final").Select
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

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