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

时间:2017-11-01 19:58:58

标签: arrays excel vba

是否有更快的版本方法将数组输出到Excel?

我目前有数据存储在3个数组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

我目前的工作解决方案是:

DropDownListDay.DataTextField = "day";
DropDownListDay.DataValueField = "patientID";

然而,即使仅 150行,这也非常缓慢。

任何提高速度的方法?

1 个答案:

答案 0 :(得分:0)

我为此编写的循环遍历日期列表和2个数字以创建一组新数据,创建3x单个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