Macro for Automatically Moving Data between Sheets

BeckySW

New Member
Joined
May 29, 2019
Messages
2
Hi there,


I have rows of data in a sheet (sheet is named "Grant") that I would like to move to a new sheet named "Archive" automatically, once "Yes" has been selected from the dropdown box in column AK (data starts at row 9) in the "Grant" sheet. I would also like it to delete the row in the "Grant" sheet, so it is not showing in two places.

Hopefully this makes sense, please help!!!





Thanks in advance.
 

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.
Hi. Try this. Use it on a dummy workbook first.

Code:
Sub MoveToArchive()

Application.ScreenUpdating = False
 
Dim lr As Long, lrArch As Long

lrArch = Sheets("Archive").Range("AK" & Sheets("Archive").Rows.Count).End(xlUp).Row + 1
With Sheets("Grant")
    If .AutoFilterMode Then .AutoFilterMode = False
    lr = .Range("AK" & .Rows.Count).End(xlUp).Row
    If lr < 9 Then Exit Sub
    With .Range("AK8:AK" & lr)
        .AutoFilter
        .AutoFilter Field:=1, Criteria1:="Yes"
        If .SpecialCells(xlCellTypeVisible).Count > 1 Then
            .Offset(1, 0).Resize(lr - 1).SpecialCells(xlCellTypeVisible).EntireRow.Copy
            Sheets("Archive").Range("A" & lrArch).PasteSpecial xlPasteValues
            .Offset(1, 0).Resize(lr - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
        End If
    End With
    .AutoFilterMode = False
End With

Application.ScreenUpdating = True

End Sub
 
Last edited:
Upvote 0
Thank you! Gave it a try and it keeps giving me runtime error "1004" back - says pastespecial method of range class failed. (see below)





Sub MoveToArchive()

Application.ScreenUpdating = False

Dim lr As Long, lrArch As Long
lrArch = Sheets("Archive").Range("AK" & Sheets("Archive").Rows.Count).End(xlUp).Row + 1
With Sheets("Grant")
If .AutoFilterMode Then .AutoFilterMode = False
lr = .Range("AK" & .Rows.Count).End(xlUp).Row
If lr < 9 Then Exit Sub
With .Range("AK8:AK" & lr)
.AutoFilter
.AutoFilter Field:=1, Criteria1:="Yes"
If .SpecialCells(xlCellTypeVisible).Count > 1 Then
.Offset(1, 0).Resize(lr - 1).SpecialCells(xlCellTypeVisible).EntireRow.Copy
Sheets("Archive").Range("A" & lrArch).PasteSpecial xlPasteValues (this is highlighted when debugging)
.Offset(1, 0).Resize(lr - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End If
End With
.AutoFilterMode = False
End With




I just copied over the format from the "Grant" sheet so that it would remain the same, there are also two hidden columns in this format, could that be causing issues?
 
Upvote 0
I'm not sure that is the issue but you could always try making them visible and trying again.
 
Upvote 0

Forum statistics

Threads
1,215,493
Messages
6,125,128
Members
449,206
Latest member
burgsrus

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