Hello experts.
I have some code that runs through a few thousand lines of data to look for two conditions and if found copy to a separate spreadsheet to load into a listbox. I'm sure there are many better ways to achieve this which is why I'm reaching out for assistance. I've tried all the usual things to speed it up, but am now at a loss. Currently it takes about 30-40 seconds to complete to even show the userform.
Specifics:
* 2 worksheets (CMR's 2018 and CMR Tracking)
* 26 columns used across
* a few thousand rows (sheet will be used for entire year)
What it's looking for:
If column Y has a date and Z does not (Return the row)
If column W has a name and Y has no date (Return the row)
Here's the code - please suggest away!
Sub OutstandingWOs() Dim y As Range Dim i As Long Dim lastColumn As Integer Dim lastRowSource As Long Dim lastRowDestination As Long Dim wsSource As Worksheet Dim wsDestination As Worksheet Set wsSource = Sheets("CMRs " & Year(Now)) Set wsDestination = Sheets("CMR Tracking") lastColumn = wsSource.Cells(1, Columns.Count).End(xlToLeft).Column lastRowSource = wsSource.Range("F" & Rows.Count).End(xlUp).Row lastRowDestination = wsDestination.Range("F" & Rows.Count).End(xlUp).Row + 1 Application.ScreenUpdating = False EventState = Application.EnableEvents Application.EnableEvents = False CalcState = Application.Calculation Application.Calculation = xlCalculationManual PageBreakState = ActiveSheet.DisplayPageBreaks ActiveSheet.DisplayPageBreaks = False wsDestination.Range("A2:Z" & lastRowDestination).ClearContents i = 2 For Each y In wsSource.Range("Y2:Y" & lastRowSource) If Not IsEmpty(y) And y.Offset(0, 1) = "" Or IsEmpty(y) And y.Offset(0, -2) <> "" Then y.EntireRow.Copy wsDestination.Cells(i, 1) i = i + 1 Else End If Next Set wsSource = Nothing Set wsDestination = Nothing ActiveSheet.DisplayPageBreaks = PageBreakState Application.Calculation = CalcState Application.EnableEvents = EventState Application.ScreenUpdating = True End Sub
Bookmarks