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!
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!