我编写了一个代码来匹配数据(MaterialPN 与 MaterialPS 和 WeekPN 与 WeekPS)并在两张纸之间复制适当的值(包装需求 - PN 和包装暂存 - PS)。
我已经关闭了 ScreenUpdating、Calculations 和 Events。这使得运行时间从 5 分钟缩短到 1 分钟,这仍然很慢(我的数据只有约 3000 行)。我还尝试使用 GoTo Flag1 在 WeekPN 不等于 WeekPS 时强制退出 If 语句,但这并没有使我的代码运行得更快。
有关如何使此代码更高效的任何提示?
提前感谢您的帮助!
Sub PackagingNeeds2PackagingStaging()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
With Sheets("Packaging Needs")
i = .Cells(.Rows.Count, 5).End(xlUp).Row
End With
With Sheets("Packaging Staging")
l = .Cells(.Rows.Count, 1).End(xlUp).Row
End With
j = 25
For k = 9 To i
For x = 5 To l
For Z = 14 To j
MaterialPN = Sheets("Packaging Needs").Cells(k, 5).Value
MaterialPS = Sheets("Packaging Staging").Cells(x, 1).Value
WeekPN = Sheets("Packaging Needs").Cells(4, Z).Value
WeekPS = Sheets("Packaging Staging").Cells(x, 12).Value
If WeekPN <> WeekPS Then GoTo Flag1
If WeekPN = WeekPS Then
If MaterialPN = MaterialPS Then
Sheets("Packaging Staging").Cells(x, 19).Value = Sheets("Packaging Needs").Cells(k, Z).Value
End If
End If
Flag1:
Next
Next
k = k + 5
Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
End Sub