Cut/Paste row from Sheet1 to Sheet2, delete empty row on Sheet1?

Sadsmileyface

New Member
Joined
Mar 21, 2013
Messages
11
I'm looking to cut and paste a row from one worksheet to another within a spreadsheet if a particular cell is not blank. Then once complete, delete the original row.

If cell AM2 (and AM3,4,5 etc) on sheet 'Faults' is not blank, cut either the whole row or the range A2:AN2 (whichever is more efficient) and paste it into the next empty row on sheet 'Archive'. So each time the macro runs, it will append to the bottom of the range on 'Archive', meaning I get to keep everything and not overwrite it.


I found this online and made some changes, but I can only get it to copy and paste some of the columns rather than all, and it doesn't cut or delete:

Code:
Sub Archive() With Worksheets("Faults") '<--| change "OriginWs" to your actual data worksheet name
        With .Range("AM2", .Cells(.Rows.Count, "AM").End(xlUp))
            .AutoFilter Field:=1, Criteria1:=">0"
            If Application.WorksheetFunction.Subtotal(103, .Resize(, 1)) > 1 Then .Offset(1, -8).Resize(.Rows.Count - 1, 11).SpecialCells(xlCellTypeVisible).Copy Worksheets("Sheet1").Cells(1, 1) '<--| change "TargetWs" to your actual destination worksheet name
            End With
        .AutoFilterMode = False
    End With
End Sub

Any advice is always appreciated.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Does this get you any closer to what you want... This code will delete data, please test on a copy of your worksheet.

Code:
Sub Archive()


    Dim rng As Range
    Dim FlRow As Long, AlRow As Long
    
    FlRow = Worksheets("Faults").Cells(Rows.Count, "AM").End(xlUp).Row
    AlRow = Worksheets("Archive").Cells(Rows.Count, "A").End(xlUp).Row
    With Worksheets("Faults")
        Set rng = .Range("A1:AN" & FlRow)
        With rng
            .AutoFilter Field:=39, Criteria1:=">0"
            .Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy
            Worksheets("Archive").Range("A" & AlRow + 1).PasteSpecial Paste:=xlPasteAll
            Application.CutCopyMode = False
            rng.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
        End With
        .AutoFilterMode = False
    End With
    
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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