Hi all,
This is my first post, so please bear with me. I'm definitely not good at VBA, but I'm continuing to learn as I design new templates and I use forums like these.
In the code below, I am taking any items that were delivered late on the "summary" worksheet and moving them to a list on the "delivered late" worksheet. The code looks for any item coded as delivered late, copies the row, pastes the row on the other sheet, deletes the original row, and looks again. My problem is that if I have something on the list, the code is overwriting it instead of adding at the bottom of the list. I have tried different things I found online, but I am always generating an error.
Thank you for your assistance. Here is the code I have:
Sub SpecialCopy()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
On Error GoTo Err_Execute
Application.ScreenUpdating = False
LSearchRow = 8
LCopyToRow = 8
While Len(Range("B" & CStr(LSearchRow)).Value) > 0
If Range("I" & CStr(LSearchRow)).Value = "DELIVERED - LATE" Then
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
Sheets("Delivered late").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste
LCopyToRow = LCopyToRow + 1
Sheets("Summary").Select
End If
LSearchRow = LSearchRow + 1
Wend
LastRow = Cells(Rows.Count, "I").End(xlUp).Row
For i = LastRow To 1 Step -1
If Range("I" & i).Value = "DELIVERED - LATE" Then
Range("I" & i).EntireRow.Delete
End If
Next I
Application.CutCopyMode = False
Range("B8").Select
MsgBox "All matching data has been copied."
Exit Sub
Err_Execute:
MsgBox "An error occurred."
End Sub
This is my first post, so please bear with me. I'm definitely not good at VBA, but I'm continuing to learn as I design new templates and I use forums like these.
In the code below, I am taking any items that were delivered late on the "summary" worksheet and moving them to a list on the "delivered late" worksheet. The code looks for any item coded as delivered late, copies the row, pastes the row on the other sheet, deletes the original row, and looks again. My problem is that if I have something on the list, the code is overwriting it instead of adding at the bottom of the list. I have tried different things I found online, but I am always generating an error.
Thank you for your assistance. Here is the code I have:
Sub SpecialCopy()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
On Error GoTo Err_Execute
Application.ScreenUpdating = False
LSearchRow = 8
LCopyToRow = 8
While Len(Range("B" & CStr(LSearchRow)).Value) > 0
If Range("I" & CStr(LSearchRow)).Value = "DELIVERED - LATE" Then
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
Sheets("Delivered late").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste
LCopyToRow = LCopyToRow + 1
Sheets("Summary").Select
End If
LSearchRow = LSearchRow + 1
Wend
LastRow = Cells(Rows.Count, "I").End(xlUp).Row
For i = LastRow To 1 Step -1
If Range("I" & i).Value = "DELIVERED - LATE" Then
Range("I" & i).EntireRow.Delete
End If
Next I
Application.CutCopyMode = False
Range("B8").Select
MsgBox "All matching data has been copied."
Exit Sub
Err_Execute:
MsgBox "An error occurred."
End Sub