chelsea199999
New Member
- Joined
- Apr 3, 2022
- Messages
- 2
- Office Version
- 2016
- Platform
- Windows
I have to work with an Excel File every week that contains dates of signed contracts. The file varies in size depending on the week. The dates are always listed in Column K of the spreadsheet in randomized order.
I would like to have a macro that automates the clean-up. Mainly, one that 1) autofilters out dates before a given date, and 2) sorts the results (sans header) in chronological order (oldest to newest).
I have tried to code it myself with the following VBA:
However, whenever I run the code, an error message pops up. I am very new to VBA coding, may anyone please offer some guidance?
I would like to have a macro that automates the clean-up. Mainly, one that 1) autofilters out dates before a given date, and 2) sorts the results (sans header) in chronological order (oldest to newest).
I have tried to code it myself with the following VBA:
VBA Code:
Sub Sortdate()
Dim Ac As Integer
Dim Lastr As Long
Dim Sh As Worksheet
Dim sDate As String
Set Sh = ActiveSheet
Ac = ActiveCell.Column
Lastr = Sh.Cells(Rows.Count, Ac).End(xlUp).Rows
Date = InputBox("Please Enter Deal Expration Date.")
Selection.AutoFilter
Range(Cells(2, Ac), Cells(Lastr, Ac)).AutoFilter Field:=11, Criteria1:= _">" & CDate(sDate)
With Sh
Range(Cells(2, Ac), Cells(Lastr, Ac)).Sort Key1:=Range(Cells(2, Ac), Cells(Lastr, Ac)), Order1:=xlAscending, DataOption1:=xlSortNormal, MatchCase:=False, SortMethod:=xlPinYin, _Header:=xlYes, Orientation:=xlTopToBottom.Sort.Apply
End With
End Sub