MJaspering
New Member
- Joined
- Oct 2, 2023
- Messages
- 8
- Office Version
- 365
- 2021
- Platform
- Windows
Hey All,
I am looking to move table rows from a table (SalesTable) on one tab "Sales" to another table (ArchiveTable) on another tab "Archive" based on the content of a the final cell. Ideally this would also create a new row in the SalesTable to ensure that the main table stays populated with blanks rows.
I would be looking to move the Sales table cells from range B:P to end of the Archive Table when the cell in Column P equals "ARCHIVE"
I found the code below which I am feeling a bit lost on how to customize this to my needs.
I am looking to move table rows from a table (SalesTable) on one tab "Sales" to another table (ArchiveTable) on another tab "Archive" based on the content of a the final cell. Ideally this would also create a new row in the SalesTable to ensure that the main table stays populated with blanks rows.
I would be looking to move the Sales table cells from range B:P to end of the Archive Table when the cell in Column P equals "ARCHIVE"
I found the code below which I am feeling a bit lost on how to customize this to my needs.
VBA Code:
Option Explicit
Public Sub moveTableRows()
Dim wb As Workbook
Dim ws As Worksheet
Dim tabStart As ListObject, tabProgress As ListObject, tabComp As ListObject
Dim statusCol As Range
Dim i As Long
Set wb = ThisWorkbook
Set ws = wb.ActiveSheet
Set tabStart = ws.ListObjects("Started")
Set tabProgress = ws.ListObjects("InProgress")
Set tabComp = ws.ListObjects("Completed")
Set statusCol = tabStart.ListColumns("status").DataBodyRange
For i = tabStart.ListRows.Count To 1 Step -1
If statusCol(i).Value = "In Progress" Then
addTableRow tabStart.DataBodyRange.Rows(i).Value, tabProgress
tabStart.ListRows(i).Delete
ElseIf statusCol(i).Value = "Completed" Then
addTableRow tabStart.DataBodyRange.Rows(i).Value, tabComp
tabStart.ListRows(i).Delete
End If
Next i
End Sub
Public Sub addTableRow(sourceData As Variant, tabDest As ListObject)
tabDest.ListRows.Add
tabDest.DataBodyRange.Rows(tabDest.ListRows.Count).Value = sourceData
End Sub