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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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

al_b_cnu

Well-known Member
Joined
Jul 18, 2003
Messages
4,526
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

Titian

Well-known Member
Joined
Dec 17, 2004
Messages
567
Thanks guys, VoG gives me the answer I was looking for.

Thanks Alan for your interest too
 
Upvote 0

Forum statistics

Threads
1,190,913
Messages
5,983,532
Members
439,848
Latest member
timmyo

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