hello,
I am currently having issues matching a date from an oracle database to yesterday's date using the vba date function. If I run the macro I want it to search the spreadsheet for yesterday's date(friday's date if its a monday) and copy all of those rows into a new sheet. So far the code will find the date but I am having issues matching the dates. The date format from the sheet is '3/20/2013 11:00:00 PM' Thanks for any help.
Sub datesearch()
Dim ThisDay As Date, PrevDay As Date
Application.DisplayAlerts = False
Err.Clear
On Error Resume Next
Set ws = Sheets("Active Jobs")
If Err = 0 Then
ws.Delete
End If
Sheets("stagehours").Activate
ThisDay = Date
ThisDay = Format([A1], "m/d/yyyy")
If Weekday(ThisDay) = vbMonday Then
PrevDay = ThisDay - 10
Else
PrevDay = ThisDay - 1
End If
Sheets("stagehours").Range("O:O").AutoFilter Field:=15, Criteria1:=PrevDay
Cells.Select
Selection.Copy
Sheets.Add(After:=Sheets("stagehours")).Name = "Active Jobs"
Range("A1").Select
ActiveSheet.Paste
Sheets("stagehours").ShowAllData
End Sub
Bookmarks