VBA - Move rows from one sheet to another based on criteria without replacing

ExcelHelpPls

New Member
Joined
Jun 20, 2011
Messages
10
Hi all,

I have very little experience with VBA but was able to find the below code and adjust it to sort of meet my needs. I have two sheets with in a workbook, "All" and "Archive". The goal is when the Macro "Archive" is run, any row on the "All" sheet that has the word "Complete" in column E is moved to the "Archive" sheet. The code below does execute this, but if I run the macro again it overwrites the previous data on the "Archive" sheet. Is there a way to adjust the code to put data in the next empty cell so rows aren't overwritten?

Sub Archive()


Dim Destination As Worksheet


Application.ScreenUpdating = False


Set Destination = Worksheets("Archive")


Destination.Cells.Clear
With ActiveSheet.UsedRange
.AutoFilter field:=5, Criteria1:="Complete"
.Copy Destination:=Destination.Cells(1, "A")
On Error Resume Next
.Offset(1, 0).Resize(.Rows.Count - 1, Columns.Count).SpecialCells(xlCellTypeVisible).EntireRow.Delete
If Err.Number <> 0 Then
MsgBox "No records found..."
Destination.Rows(1).Delete
On Error GoTo 0
End If
.AutoFilter
End With


Application.ScreenUpdating = True


End Sub


Secondary question: Is there a way to adjust the code below that would allow 2 rows of headers, as opposed to one?

Thanks!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,202,983
Messages
6,052,907
Members
444,611
Latest member
ggwpnore

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