Hello me again,
I have the below code, which works perfectly to copy rows from one sheet to another based on the value of another cell.
I'm trying now to run the same sort of thing but I need to move the rows from one Workbook (main source.xlsb) to another Workbook (Archive 2023.xlsb) but I needed to be based on a date range (so basically to retain the last three months of data and move everything else to the archive my date source should be in column AB2:AB )
Just being conscious that once the main source gets to big it will slowdown the sheet.
Please let me know if this is possible and thanks again in advance.
VBA Code:
Sub MoveCellsSEA()
Dim xRg As Range
Dim xCell As Range
Dim A As Long
Dim B As Long
Dim C As Long
A = Worksheets("Files to Make Up (Sea) ").UsedRange.Rows.Count
B = Worksheets("Archive (Sea)").UsedRange.Rows.Count
If B = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("Archive (Sea)").UsedRange) = 0 Then B = 0
End If
Set xRg = Worksheets("Files to Make Up (Sea) ").Range("A2:AG" & A)
On Error Resume Next
Application.ScreenUpdating = False
For C = 1 To xRg.Count
If CStr(xRg(C).Value) = "Completed" Then
xRg(C).EntireRow.COPY
Worksheets("Archive (Sea)").Range("A" & B + 1).PasteSpecial Paste:=xlPasteValues
xRg(C).EntireRow.Delete
If CStr(xRg(C).Value) <> "" = "Completed" Then
C = C - 1
End If
B = B + 1
End If
Next
Application.ScreenUpdating = True
End Sub
Source Woorkbook.
Target Workbook.
I have the below code, which works perfectly to copy rows from one sheet to another based on the value of another cell.
I'm trying now to run the same sort of thing but I need to move the rows from one Workbook (main source.xlsb) to another Workbook (Archive 2023.xlsb) but I needed to be based on a date range (so basically to retain the last three months of data and move everything else to the archive my date source should be in column AB2:AB )
Just being conscious that once the main source gets to big it will slowdown the sheet.
Please let me know if this is possible and thanks again in advance.
VBA Code:
Sub MoveCellsSEA()
Dim xRg As Range
Dim xCell As Range
Dim A As Long
Dim B As Long
Dim C As Long
A = Worksheets("Files to Make Up (Sea) ").UsedRange.Rows.Count
B = Worksheets("Archive (Sea)").UsedRange.Rows.Count
If B = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("Archive (Sea)").UsedRange) = 0 Then B = 0
End If
Set xRg = Worksheets("Files to Make Up (Sea) ").Range("A2:AG" & A)
On Error Resume Next
Application.ScreenUpdating = False
For C = 1 To xRg.Count
If CStr(xRg(C).Value) = "Completed" Then
xRg(C).EntireRow.COPY
Worksheets("Archive (Sea)").Range("A" & B + 1).PasteSpecial Paste:=xlPasteValues
xRg(C).EntireRow.Delete
If CStr(xRg(C).Value) <> "" = "Completed" Then
C = C - 1
End If
B = B + 1
End If
Next
Application.ScreenUpdating = True
End Sub
Source Woorkbook.
Main Source.xlsb | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
N | O | P | Q | R | S | T | U | V | W | X | Y | Z | AA | AB | AC | AD | AE | AF | AG | |||
1 | File No | Origin Port | Line | Mode | USER | DOCS DL | TARIFFS | DOCS UL | C/S | BREAK DOWN | Delivery Date | Location | Reason Category (NEW) | COMMENTS | Date Completed | Target Date | Ontime/Late | Completed Month | Count | Status | ||
2 | 10887 | Chennai | COSCO | SEA | ED | Y | Y | Y | Y | Y | 44950 | MAGNA PARK | Assigned after Target Date | 06/01/2023 | 05/01/2023 | Late | Jan | 1 | Completed | |||
3 | 10900 | Chennai | COSCO | SEA | JE | Y | Y | Y | Y | Y | 44953 | MAGNA PARK | Missing Invoice | 783789 wrong info on inv - chased again 09/01 | 10/01/2023 | 12/01/2023 | On Time | Jan | 1 | Completed | ||
4 | 10909 | Nhava Sheva | MSC | SEA | ED | Y | Y | Y | Y | Y | 44953 | MAGNA PARK | 06/01/2023 | 12/01/2023 | On Time | Jan | 1 | Completed | ||||
5 | 10916 | Mundra | MSC | SEA | ED | Y | Y | Y | Y | Y | 44953 | FGS | 10/01/2023 | 12/01/2023 | On Time | Jan | 2 | Completed | ||||
6 | 10916 | Mundra | MSC | SEA | ED | Y | Y | Y | Y | Y | 44953 | FGS | 10/01/2023 | 12/01/2023 | On Time | Jan | 2 | Completed | ||||
7 | 10939 | Damietta | Hapag | SEA | JE | Y | Y | Y | Y | Y | 44953 | MAGNA PARK | Missing Declaration | Only fed in on 12/01 and added 16/01 to adhoc - NEED EUR1 - emailed supplier | 18/01/2023 | 12/01/2023 | Late | Jan | 1 | Completed | ||
8 | 10939 | Damietta | Hapag | SEA | JE | Y | Y | Y | Y | Y | 44956 | MAGNA PARK | Missing Declaration | Only fed in on 12/01 and added 16/01 to adhoc - NEED EUR1 - emailed supplier | 18/01/2023 | 12/01/2023 | Late | Jan | 1 | Completed | ||
9 | 10939 | Damietta | Hapag | SEA | JE | Y | Y | Y | Y | Y | 44956 | MAGNA PARK | Missing Declaration | Only fed in on 12/01 and added 16/01 to adhoc - NEED EUR1 - emailed supplier | 18/01/2023 | 12/01/2023 | Late | Jan | 1 | Completed | ||
10 | 10939 | Damietta | Hapag | SEA | JE | Y | Y | Y | Y | Y | 44953 | MAGNA PARK | Missing Declaration | Only fed in on 12/01 and added 16/01 to adhoc - NEED EUR1 - emailed supplier | 18/01/2023 | 12/01/2023 | Late | Jan | 1 | Completed | ||
11 | 10939 | Damietta | Hapag | SEA | JE | Y | Y | Y | Y | Y | 44956 | MAGNA PARK | Missing Declaration | Only fed in on 12/01 and added 16/01 to adhoc - NEED EUR1 - emailed supplier | 18/01/2023 | 12/01/2023 | Late | Jan | 1 | Completed | ||
12 | 10901 | Ningbo | MSC | SEA | ED | Y | Y | Y | Y | Y | 44957 | MAGNA PARK | 05/01/2023 | 15/01/2023 | On Time | Jan | 1 | Completed | ||||
13 | 10901 | Ningbo | MSC | SEA | ED | Y | Y | Y | Y | Y | 44960 | MAGNA PARK | 05/01/2023 | 15/01/2023 | On Time | Jan | 1 | Completed | ||||
14 | 10912 | Xiamen | MSC | SEA | ED | Y | Y | Y | Y | Y | 44957 | MAGNA PARK | 11/01/2023 | 15/01/2023 | On Time | Jan | 1 | Completed | ||||
15 | 10931 | Mundra | COSCO | SEA | SO | Y | Y | Y | Y | Y | 44958 | FGS | 12/01/2023 | 15/01/2023 | On Time | Jan | 2 | Completed | ||||
16 | 10931 | Mundra | COSCO | SEA | SO | Y | Y | Y | Y | Y | 44958 | FGS | 12/01/2023 | 15/01/2023 | On Time | Jan | 2 | Completed | ||||
17 | 10884 | Ho Chi Minh | MSC | SEA | ED | Y | Y | Y | Y | Y | 44957 | MAGNA PARK | 03/01/2023 | 08/03/2023 | On Time | Jan | 1 | Completed | ||||
18 | 10882 | Shanghai | Yang M | SEA | SO | Y | Y | Y | Y | Y | 44964 | MAGNA PARK | 03/01/2023 | 16/01/2023 | On Time | Jan | 1 | Completed | ||||
19 | 10882 | Shanghai | Yang M | SEA | SO | Y | Y | Y | Y | Y | 44964 | MAGNA PARK | 03/01/2023 | 18/05/2023 | On Time | Jan | 1 | Completed | ||||
Sheet1 |
Target Workbook.
Archive 2023.xlsb | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
N | O | P | Q | R | S | T | U | V | W | X | Y | Z | AA | AB | AC | AD | AE | AF | AG | |||
1 | File No | Origin Port | Line | Mode | USER | DOCS DL | TARIFFS | DOCS UL | C/S | BREAK DOWN | Delivery Date | Location | Reason Category (NEW) | COMMENTS | Date Completed | Target Date | Ontime/Late | Completed Month | Count | Status | ||
2 | ||||||||||||||||||||||
3 | ||||||||||||||||||||||
4 | ||||||||||||||||||||||
5 | ||||||||||||||||||||||
6 | ||||||||||||||||||||||
7 | ||||||||||||||||||||||
8 | ||||||||||||||||||||||
9 | ||||||||||||||||||||||
10 | ||||||||||||||||||||||
11 | ||||||||||||||||||||||
12 | ||||||||||||||||||||||
Archive SEA |