Friday, 25 October 2013

How to create and use array in excel macro


Sub createArray()
'How to create and use array in excel macro
'Arrays are used to store large number of elements in sequence

'There are 2 types of Arrays in Excel Macro
'1.Fixed Size Array
'2.Dynamic Array

'**************************Fixed Size***********************************
Dim a(11)
a(0) = "sagar"
a(1) = 2
MsgBox a(1) & a(0)

'Or you can also create array like this
a = Array("sagar", "amol", "sachin", 33, 44, 55)
'**************************Dynamic Array***********************************
Dim b()

ReDim Preserve b(3)
'Above statement will resize the array to size 4
'Preserve statement will keep the existing values in the array intact
ReDim Preserve b(6)
'Again resize array to size of 7

'This is how we can array to store any number of values.
End Sub


What do you think on above excel macro topic? Please provide your input, comments, questions on excel macro. I will try to reply as soon as possible. I value your opinion on Excel Macros.

No comments:

Post a Comment

Popular Posts

Search This Blog