Remove data from one sheet and add it to another according to date

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I'm need a macro to help me remove events that are past a date i choose so i can "Arcive" them.

so heres what I need

Sheet "Diary" holds the data i want to move

Sheet "History" is where i want it to go

Sheet "Diary" Column A has the event dates
Sheet "History" Cell A1 has the date

So I want the macro when run to
Look at the date in
Sheet "History" Cell A1

goto
Sheet "Diary" Column A and find all dates that are before that date copy those rows Columns A to H only to sheet History starting at first empty row in Column H

then delete the entire rows of the columns copied in "Diary"

hope that makes sense? please help if you can

Thanks

Tony
<strike>
</strike>
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try:
Code:
Sub CopyRows()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Sheets("Diary").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    With Sheets("Diary")
        .Range("A1:A" & LastRow).AutoFilter Field:=1, Criteria1:="<" & Sheets("Archive").Range("A1")
        .Range("A2:H" & LastRow).SpecialCells(xlCellTypeVisible).Copy Sheets("Archive").Cells(Sheets("Archive").Rows.Count, "H").End(xlUp).Offset(1, 0)
        .Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible).EntireRow.Delete
        .Range("A1").AutoFilter
    End With
    Application.ScreenUpdating = True
End Sub

I used "Archive" instead of "History" to name the destination sheet. "History" is a reserved name so Excel won't let me use it to name the sheet.
 
Last edited:
Upvote 0
Hi Mumps,
Thank you very much for this,
looks great, I'll use the name Archive then thanks for pointing it out :)
Tony
 
Upvote 0

Forum statistics

Threads
1,214,893
Messages
6,122,118
Members
449,066
Latest member
Andyg666

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