Initializing All Array Elements to 0

  • There must be a faster way than that shown below, right? Something involving:


    'For Each.....rngTemp....'


    - saw it somewhere in passing; don't quite remember. Please advise... Thanks.



    Code
    Dim V() as Double
    Dim i As Long
    
    
    ReDim V(10, 1)
            
    For i = 1 To 10
        V(i) = 0
    Next i
  • Re: Initializing All Array Elements to 0


    Hi Om Avataar,


    For Each applies to object variables.


    You could just ReDim the variable again which will reset the values to zero.


  • Re: Initializing All Array Elements to 0


    No need for the For Each... the redim alone sets all values of the array to zero.


    Code
    Sub test()
        Dim V() As Double
        ReDim V(10, 1)
    End Sub

    [SIZE="1"]Sub All_Macros(Optional control As Variant)[/SIZE]

Participate now!

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