Help With VBA to Move one Row on one Table to Another Table

Mista_sav

Board Regular
Joined
Aug 18, 2019
Messages
69
Office Version
  1. 2016
Platform
  1. Windows
  2. Web
I have identical Tables, one is called Active and one is called Completed. They are on separate Sheets, also called Active and Completed.

In column H there is an option to select the status. When someone selects "Complete - No Further Action Required" i would like it to move (then delete) this row from the table and add it to the Completed table.

Any help on a VBA to do this automatically?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Could you provide a small sample of your Active and Completed sheets using the XL2BB add in?
I dont sorry mate i have this snapshot though

1681448470173.png
 
Upvote 0
I'll assume your Completed sheet has the exact same columns as your Active sheet. Try the following on a copy of your data.

VBA Code:
Option Explicit
Sub Active_to_Completed()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Set ws1 = Worksheets("Active")
    Set ws2 = Worksheets("Completed")
    
    With ws1.Range("A1").CurrentRegion
        .AutoFilter 8, "Complete - No Further Action Required"
        If ws1.UsedRange.SpecialCells(xlCellTypeVisible).Rows.Count > 1 Then
            .Offset(1).Resize(.Rows.Count - 1).Copy ws2.Range("A" & ws2.Cells(Rows.Count, 1).End(xlUp).Row + 1)
            .Offset(1).EntireRow.Delete
        End If
        With ws1
            .ShowAllData
        End With
    End With
End Sub
 
Upvote 0
I'll assume your Completed sheet has the exact same columns as your Active sheet. Try the following on a copy of your data.

VBA Code:
Option Explicit
Sub Active_to_Completed()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Set ws1 = Worksheets("Active")
    Set ws2 = Worksheets("Completed")
   
    With ws1.Range("A1").CurrentRegion
        .AutoFilter 8, "Complete - No Further Action Required"
        If ws1.UsedRange.SpecialCells(xlCellTypeVisible).Rows.Count > 1 Then
            .Offset(1).Resize(.Rows.Count - 1).Copy ws2.Range("A" & ws2.Cells(Rows.Count, 1).End(xlUp).Row + 1)
            .Offset(1).EntireRow.Delete
        End If
        With ws1
            .ShowAllData
        End With
    End With
End Sub
This works mate. Just 2 things. It only works when i press run within the view code part. Also, it puts the data at the bottom of the completed table, can this go up top if possible?
 
Upvote 0
I could make it so it runs automatically whenever there's a change in the H column - but is that what you really want? What if someone selects "Complete - No Further Action Required" by mistake? You'd be left with the annoyance of having to remove it from the Completed sheet & returning it to the Active sheet. I'll do that if that's what you want.
 
Upvote 0
This first code inserts the moved row to row 2 of the Completed sheet..

VBA Code:
Option Explicit
Sub Active_to_Completed_V2()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Set ws1 = Worksheets("Active")
    Set ws2 = Worksheets("Completed")
    
    With ws1.Range("A1").CurrentRegion
        .AutoFilter 8, "Complete - No Further Action Required"
        If ws1.Cells(Rows.Count, 1).End(xlUp).Row > 1 Then
            .Offset(1).Resize(.Rows.Count - 1).Copy
                ws2.Range("A2").Insert xlShiftDown
                Application.CutCopyMode = False
            .Offset(1).EntireRow.Delete
        End If
        With ws1
            .ShowAllData
        End With
    End With
End Sub

This second code does the move/delete automatically when there is a change in column H of the Active sheet. Obviously, this code goes in the sheet code area of the Active sheet & not in a standard module.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("H2:H" & Cells(Rows.Count, "H").End(xlUp).Row), Target) Is Nothing Then
        On Error GoTo Escape
        Application.EnableEvents = False
        Dim ws1 As Worksheet, ws2 As Worksheet
        Set ws1 = Worksheets("Active")
        Set ws2 = Worksheets("Completed")
        
        With ws1.Range("A1").CurrentRegion
            .AutoFilter 8, "Complete - No Further Action Required"
            If ws1.Cells(Rows.Count, 1).End(xlUp).Row > 1 Then
                .Offset(1).Resize(.Rows.Count - 1).Copy
                ws2.Range("A2").Insert xlShiftDown
                Application.CutCopyMode = False
                .Offset(1).EntireRow.Delete
            End If
            With ws1
                .ShowAllData
            End With
        End With
    End If
Continue:
    Application.EnableEvents = True
    Exit Sub
Escape:
    MsgBox "Error " & Err.Number & ": " & Err.Description
    Resume Continue
End Sub
 
Upvote 0
Chefs Kiss...works perfectly thanks mate. It isnt a biggy as this shouldnt be used too much and can easily be fixed up.

Thanks again mate!
 
Upvote 0

Forum statistics

Threads
1,215,358
Messages
6,124,487
Members
449,165
Latest member
ChipDude83

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