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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,627
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
63,627
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,143,637
Messages
5,719,972
Members
422,253
Latest member
frankie2016tata

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