Automatically Move Row to Another Sheet in excel

rabia01

New Member
Joined
Jul 20, 2021
Messages
1
Office Version
  1. 365
Platform
  1. MacOS
Hi everyone,

I have an excel spreadsheet with a table on 2 sheets.

One for items to be ordered and the second for items that have been ordered.
I want to know if on the 'to be ordered' tab once its marked as complete can it automatically be moved to the 'completed' tab?
I know the basics of excel so I have tried to read previous threads but really wasn't sure.

Thank you for your help
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
give this a try on a copy of your workbook.

Assumptions:
  1. you are using tables and not simply ranges
  2. There is a column in the table that a user can enter a value to indicate the order is completed. I used column 6 of the table. you will have to adjust this to your needs as indicated by the comment in the code.
VBA Code:
Private Sub Worksheet_Change(ByVal t As Range)
    Dim comSh As Worksheet
    Dim ordSh As Worksheet
    Dim loRow As Long
    Dim nxtRow As Long
    Dim tRow As Long
    
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With
    
    Set comSh = ThisWorkbook.Sheets("Completed")
    Set ordSh = ThisWorkbook.Sheets("TB Ordered")
    
    tRow = t.Row
    
    On Error Resume Next
    If t.Column = 6 And (t.Value <> 0 Or t.Value <> "") Then 'Change this to the corresponding column number for completed items
        On Error GoTo 0
        Range(Cells(t.Row, 1), Cells(t.Row, t.Column)).Cut
        
        With comSh
            nxtRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
            .Activate
            .Range(.Cells(nxtRow, 1), .Cells(nxtRow, t.Column)).Select
            .Paste
            .Cells(1, 1).Select
        End With
        
        With ordSh
            .Activate
            loRow = tRow - .Cells(tRow, 6).ListObject.DataBodyRange.Row + 1
            .Cells(tRow, 6).ListObject.ListRows(loRow).Delete
            .Cells(1, 1).Select
        End With
    End If
    On Error GoTo 0
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top