VBA code to move row with expired date to bottom of spreadsheet

lakke2120

New Member
Joined
Aug 21, 2014
Messages
32
Hello,

I am looking for a code to move a row with a expired date in one of the columns to the bottom of my spreadsheet so that the rows on top consist of today's date followed by the future dates in ascending order. It may be easier to auto sort. As long as today's date is on top followed by future dates in ascending order. Thank you very much.

Client IDName of Individual Annual ISPRoomTime
9952Tom smith1/10/20175051:30 PM
4392rick jones1/17/20171012:30pm
9941larry bird1/23/20175052:30pm
9936ron schapel1/24/20171012:30pm
9942tom jones1/26/20171012:30pm
9964bubba shrimp1/31/20171019:00am
1617davey jones2/2/20175052:30pm
9912luke skywalker2/2/20175052:30pm
9684jennifer aniston2/9/20175052:30pm

<colgroup><col><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
See if this does what you want. I assumed that Client was in Column A and the headers were in row 1
Code:
Sub mysort()
Dim lr As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row


Cells(2, 1).Activate
    Selection.CurrentRegion.Select
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("C2:C" & lr) _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("A1:E" & lr)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
For i = lr To 2 Step -1
    If Cells(i, 3) < Date And lr > 1 Then
        Range("A" & i).EntireRow.Cut
        Range("A" & lr + 1).EntireRow.Insert shift:=xlDown
        lr = Cells(Rows.Count, 1).End(xlUp).Row
    End If
Next i
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,105
Messages
6,128,859
Members
449,472
Latest member
ebc9

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