Selection of rows (variable)

cmazur71

Board Regular
Joined
Aug 7, 2003
Messages
61
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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
66,043
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
Dim a As Long
Worksheets("Final").Select
a = Cells(Rows.Count, 1).End(xlUp).Row
Rows("2:" & a).Select
 
Solution

cmazur71

Board Regular
Joined
Aug 7, 2003
Messages
61
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
66,043
Office Version
  1. 365
Platform
  1. Windows
This line
VBA Code:
Worksheets("Final").Range("A1").Select
should be
VBA Code:
Worksheets("Final").Select
 

Forum statistics

Threads
1,148,334
Messages
5,746,162
Members
423,997
Latest member
moofish87

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