to empty array in VBA?

  • Re: to empty array in VBA?


    Check out the VBA help on Redim. If you use the Redim statement in VBA to resize the Array to zero elements it will clear all its elements... you would then need to use Redim again to resize it back to its original shape if required.


    from the VBA help....


    Quote


    If you make an array smaller than it was, data in the eliminated elements will be lost


    Look up how to use Redim in VBA Help.


    Ger

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

  • Re: to empty array in VBA?


    Hi,


    Just to add and explain a little on Ger's suggestion.
    In order to use the ReDim you will first have to Dim the variable with no dimension.
    No need to resize as ReDim will erase the values even if the size is the same.
    This quick example will output before and after values to the immediate window
    [vba]Sub test()


    Dim intArray() As Integer
    Dim intIndex As Integer

    ReDim intArray(3) As Integer

    intArray(1) = 1
    intArray(2) = 2
    intArray(3) = 3

    For intIndex = 1 To 3
    Debug.Print intArray(intIndex);
    Next
    Debug.Print


    ' clear the array
    ReDim intArray(3) As Integer

    For intIndex = 1 To 3
    Debug.Print intArray(intIndex);
    Next
    Debug.Print

    End Sub[/vba]

  • Re: to empty array in VBA?


    Cool - thanks for claryfing Andy - I misunderstood its use...


    :thanx:

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

  • Re: to empty array in VBA?


    Wow... I like it... learn something new everyday at this forum.
    :wowee: :thanx:

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!