VBA dim statement

Titian

Well-known Member
Joined
Dec 17, 2004
Messages
567
I am attempting to to use the statement
Code:
Dim customers(lr) as long

where "lr" is the number of the last row.

The statement fails with
"Compile error"
"Constant expression required"

Is it possible to load a variable into a "Dim" statement like this?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try something like

Code:
Dim customers() As Long, lr As Long
lr = Range("A" & Rows.Count).End(xlUp).Row
ReDim customers(1 To lr)
 
Upvote 0
Hi,

try:
Code:
Dim customers as Long

customers = lr

To determine the last row of, say, sheet1 column A, try
Code:
Dim customers as Long

customers=Sheets("Sheet1").Cells(rows.count,"A").end(xlUp).Row
 
Upvote 0
Thanks guys, VoG gives me the answer I was looking for.

Thanks Alan for your interest too
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,806
Members
449,337
Latest member
BBV123

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