+ Reply to Thread
Results 1 to 2 of 2

Partial Date Match/formatting error

Hybrid View

  1. #1
    Registered User
    Join Date
    03-15-2013
    Location
    Indianapolis, IN
    MS-Off Ver
    Excel 2007
    Posts
    7

    Partial Date Match/formatting error

    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

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Partial Date Match/formatting error

    It looks like your 'dates' are actually text.

    You can check that using the ISNUMBER worksheet function with one of the cells with a 'date'.

    If it returns FALSE then you have a text date.

    Even if you do have actual date values then they appear to have a time part, PrevDay won't have that so won't match.

    Are you able to filter the data manually?
    If posting code please use code tags, see here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1