简体   繁体   English

VBA阵列更快地输出到Excel工作表

[英]VBA Array Faster Output to Excel Sheet

Is there a faster version method to output an array to excel? 有没有更快的版本方法可以输出数组到excel?

I currently have data stored in 3 arrays output_dt, output_s1, output_s2 . 我目前将数据存储在3个数组output_dt, output_s1, output_s2

Format sample: 格式样本:

15/12/2017  2165    2170
15/12/2017  2165    2175
15/12/2017  2165    2180
15/12/2017  2165    2185
15/12/2017  2165    2190
15/12/2017  2165    2195
15/12/2017  2165    2200
15/12/2017  2165    2205
15/12/2017  2165    2210

My current working solution is this: 我当前的工作解决方案是这样的:

Application.ScreenUpdating = False
Worksheets("Strategies").Columns(4).ClearContents
Worksheets("Strategies").Columns(5).ClearContents
Worksheets("Strategies").Columns(6).ClearContents
[d1].Resize(UBound(output_dt)) = Application.Transpose(output_dt)
[e1].Resize(UBound(output_s1)) = Application.Transpose(output_s1)
[f1].Resize(UBound(output_s2)) = Application.Transpose(output_s2)
Application.ScreenUpdating = True

However, this is painfully slow, even for just 150 rows . 但是,这非常缓慢,即使只有150行也是如此

Any methods to speed this up? 有什么方法可以加快速度吗?

The loop I wrote for this to loop through the list of dates and 2 numbers to create a new set of data, creating 3x single 1D arrays. 我为此编写的循环遍历日期列表和2个数字以创建一组新数据,从而创建了3个单个1D数组。

    For i = LBound(data) To UBound(data)
        For j = LBound(data) To UBound(data)
            If data(i, 1) = data(j, 1) Then
                If data(i, 2) < data(j, 2) Then
                    x = x + 1
                    'MsgBox data(i, 2) & "-" & data(j, 2)
                    ReDim Preserve output_dt(0 To x + 1)
                    ReDim Preserve output_s1(0 To x + 1)
                    ReDim Preserve output_s2(0 To x + 1)
                    output_dt(x) = data(i, 1)
                    output_s1(x) = data(i, 2)
                    output_s2(x) = data(j, 2)
                End If
            End If
        Next j
    Next i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM