Hi,
I have an order report i run daily with around 20k rows with customer data, order quantity and order value. (I removed half of the data in the mockup file)
What i´m basically trying to do is copy the rows that is either incomplete in column K, or copy the rows which has a complete value in column P but no value in column S, to another sheet.
I tried to write an loop for it and it works, but considered it´s alot of rows it takes ~3-4minutes to evaluate whole range.
Is there a faster approach to this?
I have an order report i run daily with around 20k rows with customer data, order quantity and order value. (I removed half of the data in the mockup file)
What i´m basically trying to do is copy the rows that is either incomplete in column K, or copy the rows which has a complete value in column P but no value in column S, to another sheet.
I tried to write an loop for it and it works, but considered it´s alot of rows it takes ~3-4minutes to evaluate whole range.
Is there a faster approach to this?
Code:
Sub fcat()
Dim fcat As Variant, cell As Range
Dim lRow As Long
Dim RngOne As Range
Dim StartTime As Double
Dim SecondsElapsed As Double
'Remember time when macro starts
StartTime = Timer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Set src = ThisWorkbook.Sheets("Data")
Set tgt = ThisWorkbook.Sheets("SO 2017")
' hitta sista raden med data i kolumn A
lRow = src.Range("A" & src.Rows.Count).End(xlUp).Row
'Töm tabellen med order för 2017
With Sheet8.ListObjects("Table1")
If Not .DataBodyRange Is Nothing Then
.DataBodyRange.Delete
End If
End With
ii = 2
With Sheets("Data")
Set RngOne = src.Range("A6:A" & lRow)
For Each cell In RngOne
If cell.Offset(, 15) > 0 And _
cell.Offset(, 18) = 0 Or cell.Offset(, 18) = ISBLANK And cell.Offset(, 15) = 0 Then
Range(cell.Offset(0, 0), cell.Offset(0, 9)).Copy (tgt.Range("A" & ii))
If cell.Offset(, 15) > 0 Then
tgt.Range("L" & ii) = cell.Offset(, 15)
tgt.Range("K" & ii) = cell.Offset(, 12)
ElseIf cell.Offset(, 15) = 0 And cell.Offset(, 12) > 0 Then
tgt.Range("K" & ii) = cell.Offset(, 12)
Else
tgt.Range("L" & ii) = cell.Offset(, 13)
tgt.Range("K" & ii) = cell.Offset(, 10)
End If
ii = ii + 1
End If
Next cell
'Loop
End With
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
'Determine how many seconds code took to run
SecondsElapsed = Round(Timer - StartTime, 2)
'Notify user in seconds
MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation
End Sub