Simple but dynamic Range...Select statement

Ivan Howard

Active Member
Joined
Nov 10, 2004
Messages
333
Hi All,

In Cell A1, I have a count of the number of rows within a dataset, starting in A3. For this example, lets say that there is 1000 rows of data.

What I need to do is be able to create VBA code that allows the syntax to change as and when the number of rows does. The reason for this is that I am working with different size datasets and formatting 20000 rows when I only need to format 1000 can take a lot of processing time. I want to be as efficient as I can.

For example, the following code:
Code:
Range("A3:Z1000").Select


...needs to be work like this (although this doesn't work):
Code:
Dim TOTALROWS as Double
TOTALROWS = Sheets("Sheet1").Range("A1").Value
Range("A3:Z & TOTALROWS & ").Select

Would anyone be able to help me?

Thanks very much.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Something like this
Rich (BB code):
Range("A3:Z" & TOTALROWS).Select

Just make sure you initialize the value of TOTALROWS.
 
Upvote 0
Thanks very much kpark91.

I tried it, but thought some quote marks needed to be on the right of the variable.

Thanks very much.
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,768
Members
452,940
Latest member
rootytrip

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