Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

VBA-Excel: Arrays – One Dimension, Static Array

An Array is a col­lec­tion of val­ues under the same name and dif­fer­en­ti­ated using index values.

For cre­at­ing one dimen­sional sta­tic array, fol­low the below steps

  • Declare an Array
  • Store val­ues in array
  • Retrieve val­ues from array.


Declare an Array

Dim arrData(5)

Store val­ues in array

arrData(0) = “1”

arrData(1) = “2”

arrData(2) = “3”

Retrieve val­ues from array.

Msg­Box arrData(3)

Com­plete Code:

Function FnStaticSingleArray()

    Dim arrData(5)    
 arrData(0) = "1"
  arrData(1) = "2"
  arrData(2) = "3"  
  arrData(3) = "4"
  arrData(4) = "5"
  arrData(5) = "6"
  MsgBox arrData(5)

  For i = 0 To UBound(arrData)

        arrData(i) = i + 1

  Next

  MsgBox arrData(3)  

End Function

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: