2016-08-15 12 views
0

enter image description here
これは私が作成したユーザーフォームです。次に、それは入力プラットフォームとして使用されます.2016、2017などのいくつかの異なるテーブルがあります。その保存ボタンのロジックは、ユーザー入力と場所が正しいワークシートである年(日付)を検索することです。次に、そのワークシートの最後の行が検索されます。例えば、最後の行は、ユーザーフォームの最初の行は、ユーザーフォームの1001.The第二行は、行1002に保存された行に保存され、行1000でExcelでuserformの保存速度を向上させる方法VBA

....

質問

しかし、私が実際のExcelファイルでテストすると、保存速度が遅すぎます。実際のExcelファイルは大(各ワークシートの1XXXX行)です。ユーザーフォームの行を保存するのに8秒、2行を保存するのに13秒。明らかに、節約速度は受け入れられない。それを改善する方法はありますか?

If ComboBox3.Value = "2016" Then 
    Worksheets("2016").Activate 
    j = WorksheetFunction.CountA(Worksheets("2016").Range("A:A")) + 1 
    End If 

    If ComboBox3.Value = "2017" Then 
    Worksheets("2017").Activate 
    j = WorksheetFunction.CountA(Worksheets("2017").Range("A:A")) + 1 
    End If 



    '1st 



    If ComboBox4.Value = "" Then 
    Else 
    Cells(j, 1) = ComboBox434.Value 
    Cells(j, 5) = ComboBox1.Value 
    Cells(j, 4) = ComboBox2.Value 
    Cells(j, 3) = ComboBox3.Value 
    If ComboBox4.ListIndex <> -1 Then 
    Cells(j, 6) = TimeValue(ComboBox4.Value & ":" & ComboBox5.Value) 
    Cells(j, 24) = ComboBox4.Value 
    Cells(j, 25) = ComboBox5.Value 
    Else 
    Cells(j, 6) = "" 
    End If 
    Cells(j, 7) = ComboBox6.Value 
    Cells(j, 8) = ComboBox7.Value 
    Cells(j, 9) = ComboBox8.Value 
    Cells(j, 10) = TextBox2.Value 
    Cells(j, 11) = TextBox3.Value 
    Cells(j, 12) = TextBox4.Value 
    Cells(j, 13) = TextBox5.Value 
    Cells(j, 14) = TextBox42.Value 
    Cells(j, 15) = TextBox43.Value 
    Cells(j, 16) = TextBox44.Value 
    Cells(j, 17) = TextBox666.Value 

    'If ComboBox4.Value = "" Then 

    End If 

    '2nd 

    j = j + 1 

    If ComboBox9.Value = "" Then 
    Else 
    Cells(j, 1) = ComboBox434.Value 
    Cells(j, 5) = ComboBox1.Value 
    Cells(j, 4) = ComboBox2.Value 
    Cells(j, 3) = ComboBox3.Value 
    If ComboBox9.ListIndex <> -1 Then 
    Cells(j, 6) = TimeValue(ComboBox9.Value & ":" & ComboBox10.Value) 
    Cells(j, 24) = ComboBox9.Value 
    Cells(j, 25) = ComboBox10.Value 
    Else 
    Cells(j, 6) = "" 
    End If 
    Cells(j, 7) = ComboBox11.Value 
    Cells(j, 8) = ComboBox12.Value 
    Cells(j, 9) = ComboBox13.Value 
    Cells(j, 10) = TextBox6.Value 
    Cells(j, 11) = TextBox7.Value 
    Cells(j, 12) = TextBox8.Value 
    Cells(j, 13) = TextBox9.Value 
    Cells(j, 14) = TextBox45.Value 
    Cells(j, 15) = TextBox46.Value 
    Cells(j, 16) = TextBox47.Value 
    Cells(j, 17) = TextBox617.Value 
+1

データベースに変更する以外に、それについてはほとんどできません。ユーザーフォームコントロールを配列に保存してから、セルの範囲にまとめて書き出すことで、時間を節約できます。しかし、実際のロードブロッキングは、ユーザーフォームの読み取りとワークシートの書き込みだと私は思っています。 – dbmitch

+0

または 'ComboBox.LinkedCell'プロパティを使用してください – Slai

答えて

2

計算を手動に切り替えて、情報が挿入された後に計算することで、おそらく時間を節約できます。

具体的には、あなたのコードの開始時:

With Application 
    .ScreenUpdating = False 
    .EnableEvents = False 
    .Calculation = xlCalculationManual 
End With 

し、再びあなたのコードの末尾に:また

With Application 
    .ScreenUpdating = True 
    .EnableEvents = True 
    .Calculation = xlCalculationAutomatic 
End With 

、あなたはバリアント配列にデータを保存したい場合がありますワークシートに一度に挿入することができます。または、配列とサイズをから配列のサイズに変更することができます。

Cells(j, 1).resize(Ubound(arr,1), Ubound(arr,2)) = arr 'Need to check for exact syntax 

これにより、ワークシートにヒットした回数を最小限に抑えることができます。

関連する問題