Faster Way to Import Excel Spreadsheet to Array With ADO

前端 未结 2 1047
礼貌的吻别
礼貌的吻别 2020-12-12 01:45

I am trying to import and sort data from a large excel report into a new file using Excel 2007 VBA. I have come up with two methods so far for doing this:

2条回答
  •  悲哀的现实
    2020-12-12 02:07

    i think that @Mr. Mascaro is right the easiest way to past your data from a Recordset into a spreadsheet is:

    Private Sub PopArray()
        .....
        Set rs = dbConnection.Execute("SELECT * FROM [" & SourceRange & "]")  
        '' This is faster
        Range("A1").CopyFromRecordset rs
        ''Arr = rs.GetRows
    End Sub
    

    but if you still want to use Arrays you could try this:

    Sub ArrayTest  
    
    '' Array for Test
    Dim aSingleArray As Variant  
    Dim aMultiArray as Variant  
    
    '' Set values 
    aSingleArray = Array("A","B","C","D","E")  
    aMultiArray = Array(aSingleArray, aSingleArray)
    
    '' You can drop data from the Array using 'Resize'
    '' Btw, your Array must be transpose to use this :P
    Range("A1").Resize( _
                UBound(aMultiArray(0), 1) + 1, _  
                UBound(aMultiArray, 1) + 1) = Application.Transpose(aMultiArray)
    
    End Sub
    

提交回复
热议问题