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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
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,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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