In the microsoft site:
http://msdn.microsoft.com/en-us/library/vstudio/wak0wfyt.aspx#BKMK_DeclaringAnArray
It says I can initialize an array like this:
Dim doubles = {1.5, 2, 9.9, 18}
But I'm getting error:
Compile error: Expected: end of statement
And it points to the equals sign. I'm merely copy-pasting, what's wrong here?
This error has the following cause and solution: The syntax you specified is appropriate for an array, but no array with this name is in scope. Check to make sure the name of the variable is spelled correctly. Unless the module contains Option Explicit, a variable is created on first use.
Go to the VBA toolbar and click on Tools and then click on Options. In the Options dialog box, click on the General tab and make sure that within the 'Error Trapping' group, 'Break on Unhandled Errors' is checked.
Use a Static, Dim, Private, or Public statement to declare an array, leaving the parentheses empty, as shown in the following example. Use the ReDim statement to declare an array implicitly within a procedure. Be careful not to misspell the name of the array when you use the ReDim statement.
By default, an array is indexed beginning with zero, so the upper bound of the array is 364 rather than 365. To set the value of an individual element, you specify the element's index.
This would work in vb or vb.net but not vba. You need to initialise this in two steps.
Dim doubles
doubles = array(1.5, 2, 9.9, 18)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With