2017-10-05 91 views
0

當前代碼正在查看7000+行。vba加速性能

我有問題,它崩潰。

任何人都可以幫助提高性能。即時消息VBA

很新

將使用數組這裏是useful-如果是這樣,請大家幫幫忙

Dim mrow As Long, ARow As Long, i As Long 
Dim AG_Label As String, M_Label As String 
Dim Count As Integer 
Dim AG_sht As Worksheet, M_sht As Worksheet 

    Set AG_sht = Worksheets("AG") 
    Set M_sht = Worksheets("Mappings") 
    Set SNL_sht = Worksheets("SNL") 



    Count = 2 

    ARow = AG_sht.Range("B" & Sheets("AG").Rows.Count).End(xlUp).Row 
     For i = 2 To ARow 
     AG_Label = AG_sht.Cells(i, "N").Value 
     On Error Resume Next 
     mrow = M_sht.Range("C" & Rows.Count).End(xlUp).Row + 1 
     'For j = 2 To mrow 
      'M_Match_1 = Sheets("Mappings").Cells(j, "P").Value 
      M_Label = M_sht.Cells(Count, "C").Value 

      If AG_Label = M_Label And M_sht.Cells(Count, "L").Value = "FRY-9C" Then 
       M_sht.Cells(Count, "J").copy 
       AG_sht.Cells(i, "AM").PasteSpecial Paste:=xlPasteValues, _ 
        Operation:=xlNone, SkipBlanks:=False, Transpose:=False 
      End If 
        If i = ARow Then 
         Count = Count + 1 
         M_Label = Count 
         If mrow <> "" Then 
          i = 2 
         If Count = mrow Then Exit For 
         End If 
        End If 
    Application.CutCopyMode = False 

    Next 

    Call match2 

End Sub 
+2

您是否在發佈的代碼之外的某處設置了'Application.ScreenUpdating = False?否則,這總是一個開始的好地方。 – jcarroll

+0

*目前代碼正在查看7000多行* ...並對行做了什麼?提供完整的解釋背景。另外還有一個未知的函數叫做match2 *。 – Parfait

+0

如果您先消除崩潰,然後再處理性能,那麼該怎麼辦......先告訴我們它崩潰的位置以及出現哪個錯誤 – jsotola

回答

0

立即節省時間,我會建議,而不是通過使用複製/粘貼循環的,看看如何將值分配給目標列。類似於:

If AG_Label = M_Label And M_sht.Cells(Count, "L").Value = "FRY-9C" Then 
      M_sht.Cells(Count, "J").Value = AG_sht.Cells(i, "AM").Value 
     End If 

我認爲複製/粘貼會導致很多低效率。