Defining a Variable Length Range in VBA

serubenstein

New Member
Joined
Feb 25, 2011
Messages
1
I am new to VBA / Excel Macros and would like to request some programming assistance.

I have defined a counter for the number of rows in a spreadsheet (rowCount) using the CountA worksheet function.

My next step is to define a range using this value (# of rows) to perform several operations like formating the column and copying a formula down the length of the column.

This is where I am currently (trying to define the format to the range) which isn't the correct syntax:

Range("AB2").Select
Range("AB2", "AB(rowCount)").Select
Selection.NumberFormat = "[$-409]d-mmm-yy;@"

Any assistance would be greatly appreciated.

Thank you.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Welcome to the board...

Try

Range("AB2", Range("AB" & rowCount)).NumberFormat = "[$-409]d-mmm-yy;@"
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,736
Members
452,940
Latest member
Lawrenceiow

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