Array in VBA

P

Piotr Nowak

Hi
How can I change the size of array in VBA ?
Is it possible to change static array or dynamic array ?
Please, help me.

THANKS !

Best regards,
Piotr
 
J

Jurgen

Piotr said:
Hi
How can I change the size of array in VBA ?

Use the "redim" statement the change the size.
eg
Dim MyArray(2,2) as string
ReDim MyArray(5, 5) as string

Use "redim preserve" if you want to keep the data stored in the array after
resizing it. Note that you can only change the LAST dimension when using
"preserve"

succes,
 
P

Piotr

Hi Jurgen
Thanks, but is it possible to STATIC arrays ?
I get the error, but when I use dynamic arrays it's oki.

Best regards,
Piotr
 
T

Tushar Mehta

As Jurgen pointed out, use ReDim. However, the example is not correct.
One cannot redimension an array declared with specific bounds. Use
something like:

Sub testIt2()
Dim MyArray() As String
ReDim MyArray(5, 5) As String
End Sub

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
T

Tushar Mehta

Also check the responses in .excel.programming.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top