簡體   English   中英

VBA陣列更快地輸出到Excel工作表

[英]VBA Array Faster Output to Excel Sheet

有沒有更快的版本方法可以輸出數組到excel?

我目前將數據存儲在3個數組output_dt, output_s1, output_s2

格式樣本:

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

我當前的工作解決方案是這樣的:

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

但是,這非常緩慢,即使只有150行也是如此

有什么方法可以加快速度嗎?

我為此編寫的循環遍歷日期列表和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