VBA: Move row to bottom of sheet after current date has passed

munsent

New Member
Joined
Mar 17, 2025
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I want to move the top row down to the bottom of the sheet once the current date has passed. I think VBA code would work best, but am new to using VBA. I am attaching a mini sheet. I see code in previous posts for moving a row to a new sheet or to delete the row once it is moved. I need the row to remain intact. Any assistance would be appreciated.

DWU-KERNEL ACTIVITIES.xlsx
ABCDEFG
1DWU Baseball
2Date TimeOpponentProducerCamera PersonAnnouncer
33/2/202512:00 PMNorthern StateCalebZachCaleb
43:00 PMNorthern StateCalebZachCaleb
5
63/18/20253:00 PMDakota State
7
83/21/202512:00 PMHastingsDane
92:30 PMHastingsDane
10
113/25/2025TBAValley City State
12
133/29/20251:00 PMDoane
143:30 PMDoane
15
164/5/20251:00 PMMount Marty
173:00 PMMount Marty
18
194/6/20251:00 PMMount MartyZach
203:00 PMMount MartyZach
21
224/12/2025TBANorthwestern
23TBANorthwestern
24
254/13/20251:00 PMMorningside
263:30 PMMorningside
27
284/19/2025TBABriar Cliff
29TBABriar Cliff
30
31
32
Sheet2
 
I would recommend that your data include the date on every row of data. I also recommend that you get rid of blank rows.

Also, never use merged cells.

You could also combine A & B into a single date/time value, although that's not strictly needed.

What you are asking could be done with VBA but I am not a fan of physically moving around data to indicate its status.

My suggestion is to add a new column called PASSED with the following formula:
=A3<TODAY()
It will show TRUE or FALSE.

Then select all the columns and apply AutoFilter.

Then sort first by PASSED then by Date. Repeat the sort as needed. If aboslutely required, the sort could be automated with VBA, which would be much simpler to write if you make the changes as above.

$scratch.xlsm
ABCDEFGH
1DWU Baseball
2DateTimeOpponentProducerCamera PersonAnnouncerPASSED
33/18/20253:00:00 PMDakota StateFALSE
43/21/202512:00:00 PMHastingsDaneFALSE
53/21/20252:30:00 PMHastingsDaneFALSE
63/25/2025TBAValley City StateFALSE
73/29/20251:00:00 PMDoaneFALSE
83/29/20253:30:00 PMDoaneFALSE
94/5/20251:00:00 PMMount MartyFALSE
104/5/20253:00:00 PMMount MartyFALSE
114/6/20251:00:00 PMMount MartyZachFALSE
124/6/20253:00:00 PMMount MartyZachFALSE
134/12/2025TBANorthwesternFALSE
144/12/2025TBANorthwesternFALSE
154/13/20251:00:00 PMMorningsideFALSE
164/13/20253:30:00 PMMorningsideFALSE
174/19/2025TBABriar CliffFALSE
184/19/2025TBABriar CliffFALSE
193/2/202512:00:00 PMNorthern StateCalebZachCalebTRUE
203/2/20253:00:00 PMNorthern StateCalebZachCalebTRUE
munsent
Cell Formulas
RangeFormula
H3:H20H3=A3<TODAY()


1742352406432.png
 
Upvote 0
VBA approach :

VBA Code:
Option Explicit

Sub MoveOldRows()
    Dim ws As Worksheet
    Dim lastRow As Long, destRow As Long, i As Long
    Dim currentDate As Date

    ' Set the worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name

    ' Get the current date
    currentDate = Date

    ' Find the last used row in the worksheet
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

    ' Find the first unused row at the bottom for moved rows
    destRow = lastRow + 1

    ' Loop through rows from bottom to top
    For i = lastRow To 2 Step -1
        ' Check if the cell in column A contains a date older than the current date
        If IsDate(ws.Cells(i, "A").Value) And ws.Cells(i, "A").Value < currentDate Then
            ' Copy the entire row to the destination row
            ws.Rows(i).Copy Destination:=ws.Rows(destRow)
            ' Increment the destination row
            destRow = destRow + 1
            ' Delete the original row
            ws.Rows(i).Delete
        End If
    Next i

    ' Delete any blank rows (optional)
    For i = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row To 2 Step -1
        If Application.WorksheetFunction.CountA(ws.Rows(i)) = 0 Then
            ws.Rows(i).Delete
        End If
    Next i

    MsgBox "Rows moved and blank rows deleted!", vbInformation
End Sub
 
Upvote 0

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