Can I define an array constant?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,532
Office Version
  1. 365
Platform
  1. Windows
Is there a way I can define an array constant?

I tried to use the Array function

VBA Code:
Const cols As Variant = Array(1, 4, 7, 10, 13)

but it gets an error that it expected a constant expression. Seems like that is a constant expression to me, but what do I know?

I know I can define a constant list and then use Split to turn into an array, but that is not a constant.

Any other ways?
 
That structure is not a VBA construct...
I'm sure you are right. But those are details "under the hood". IMHO, VBA should provide array constants. Whatever they need to do to make that happen, they should do. That's why they pay those M$FT developers. No?

Anyway, I'm going to go with a string constant that I split into an array. The constants of the array can be changed (not read only like a constant), but close enough for what I need. However, I am having trouble with that, too. So if you have time, tell me what I am doing wrong with Split? (sigh)
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
You haven't told us how you attempted to use Split when it didn't work for you.
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

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