Move Row(s) Based On Today's Date

ccm123

New Member
Joined
Jun 28, 2018
Messages
4
Hi,

Totally new to using VBA but really need a script to be able to do the following:

I have a sheet named "Calendar" that has a row for each day of the year in order to plan and prepare social media posts for specific days. I have a second sheet named "Archive" where I would like the already posted days to move, ergo I need a script to check the date against the date in the first sheet's column C and if it is a date that has already passed then cut and paste the whole row to the Archive sheet.

I have scoured forums and sites online and played around with some solutions that have helped people with similar queries to no avail, so would greatly appreciate it if someone could help me out.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
try this on a copy of your file

Code:
Sub move_it()

Dim rs As Worksheet
Set rs = Worksheets("Archive")
lr = Cells(Rows.Count, "A").End(xlUp).Row

For r = 2 To lr

If Cells(r, "C") < [C1] Then
    wr = rs.Cells(Rows.Count, "A").End(xlUp).Row + 1
    Rows(r).Cut Destination:=rs.Range("A" & wr)
End If

Next r
End Sub

hth,
Ross
 
Last edited:
Upvote 0
Try this macro. It assumes that you have headers in row 1 of the "Calendar" sheet and that the data starts in row 2.
Code:
Sub MoveRows()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Sheets("Calendar").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Sheets("Archive").UsedRange.ClearContents
    Sheets("Calendar").Range("C1:C" & LastRow).AutoFilter Field:=1, Criteria1:="<" & Date
    Sheets("Calendar").Range("C2:C" & LastRow).SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets("Archive").Cells(1, 1)
    Sheets("Calendar").Range("C2:C" & LastRow).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    If Sheets("Calendar").AutoFilterMode Then Sheets("Calendar").AutoFilterMode = False
End Sub
 
Upvote 0
Hi,

Thanks so much for your help. I'm getting an error ('We can't do this to a merged cell') - based on some of the limitations with merged cells I've run into in the past I'm going to assume it is not possible to do this to a merged cell at all? Have attached a screenshot of the ideal setup so you can get an idea.

This macro is, however, doing the trick when I make the file with no merged cells which is great! Thank you a lot.
 
Upvote 0
Forgot to add the image, oops! Here it is.
L54Mbm2
L54Mbm2
https://imgur.com/a/L54Mbm2
 
Upvote 0
Hi,

Thanks for your help! When I tried this, it moved the entire 'Calendar' sheet to the 'Archive' sheet and then was giving the error along the lines of no cells found. In any case, thanks for taking the time to help but I have found a solution thanks to Ross' answer above.
 
Upvote 0

Forum statistics

Threads
1,215,216
Messages
6,123,669
Members
449,114
Latest member
aides

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