2015-06-16 38 views
0
With ThisWorkbook.Worksheets("test") 
    Lastrow = .Cells(.Rows.count, 2).End(xlUp).Row 
     For i = LBound(sPrincipal) To (UBound(sPrincipal) - 3) 
       .Cells((Lastrow + 1), 1) = sPrincipal(i) 
       .Cells((Lastrow + 1), 2) = sInterest(i) 
       .Cells((Lastrow + 1), 3) = sBalance(i) 
        Lastrow = Lastrow + 1 
     Next i 
End With 

大約有10萬行(列數多於此處顯示的數量)需要定期填寫,並且需要加快速度,因爲這需要超過2-3小時。任何人都可以建議是否有辦法加快這個過程。提前致謝。在VBA中提高時間

+1

什麼是sprrinciple?範圍?數組?變量?是其他變量是相同類型的嗎? – Degustaf

+2

您的代碼的慢位將與表單交互,將其全部讀入數組,然後輸出作爲一個互動,你也可以使用screnupdating和計算,但是記得在 – 99moorem

+0

@Degustaf之後重新打開它們對不起,這些都是數組。 – Meesha

回答

2
dim entries as Integer 

entries = UBound(sPrinciple) - LBound(sPrinciple) 
With ThisWorkbook.Worksheets("test") 
    Lastrow = .Cells(.Rows.count, 2).End(xlUp).Row 
    .Cells((Lastrow + 1), 1).Resize(entries, 1).Value = _ 
     WorksheetFunction.Transpose(sPrinciple) 
    .Cells((Lastrow + 1), 2).Resize(entries, 1).Value = _ 
     WorksheetFunction.Transpose(sInterest) 
    .Cells((Lastrow + 1), 3).Resize(entries, 1).Value = _ 
     WorksheetFunction.Transpose(sBalance) 
End With 

這確實有,你只能在一個時間貼65536行的缺點(在Excel 2003中的行限制。我會建議分批在那裏處理,在一時間許多行,直到完成運行代碼整個數據集