Compile Error: Constant Expression Required

lkrznchc

New Member
Joined
Feb 28, 2013
Messages
11
I am receiving an error message "Constant Expression Required" from the following code:
Code:
    num_xmitters = ThisWorkbook.Worksheets("Instr List").UsedRange.Rows.Count
    Dim TransmitterArray(1 To 4, 1 To num_xmitters) As Range

I do not feel that this range is varying since the used range on that sheet is not changing during code execution. I do want the array to be able to by dynamic and respond to however many rows are in the "Instr List" worksheet. Is there a better way of counting the number of rows used on that sheet that would avoid this error?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hello,

That is because "num_xmitters" is not declared as a constant.

You cannot use a variable in an array declaration (even if its value remains invariable).

What you could do is use the redim statement to redimension the array to the desired size.

Cheers;
drW
 
Upvote 0

Forum statistics

Threads
1,216,756
Messages
6,132,520
Members
449,733
Latest member
Nameless_

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