Sunday, July 24, 2011

Filling Array With Loop :

if you have Data in A1:C5 Range and You Need to Store that in A Variable , You can take help with this Macro :


Option Base 1
Sub StoreInArrya()
    Dim Arr() As Variant
    Dim rng As Range
    Dim Rw As Integer
    Dim Cl As Integer
   
    Set rng = Range("A1:C5")
    ReDim Arr(rng.Cells.Rows.Count, rng.Cells.Columns.Count)
       
            For Rw = 1 To rng.Rows.Count
                    For Cl = 1 To rng.Columns.Count
                    Arr(Rw, Cl) = rng.Cells(Rw, Cl).Value
                    Next
            Next
              
               For Rw = 1 To rng.Rows.Count
                    For Cl = 1 To rng.Columns.Count
                    st = st & vbTab & Arr(Rw, Cl)
                    Next
                    st = st & vbCrLf
                Next
               MsgBox st
End Sub

No comments: