+ Reply to Thread
Results 1 to 4 of 4

Check column for yesterday's date

Hybrid View

  1. #1
    Registered User
    Join Date
    01-09-2012
    Location
    here
    MS-Off Ver
    Excel 2003
    Posts
    68

    Check column for yesterday's date

    hi all,
    im trying to write an if stament to check for yest date in coulmn AD. what i wrote so far it not working properly. any help would be great thanks!!!




    
    Sub Macro1()
    
    
        Range("AD1:AD10000").Select
            
             If Date = Date - 1 Then
                MsgBox "date is correct"
                Else
                MsgBox "date is incorrect"
                End If
             
    
    End Sub

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Check column for yesterday's date

    This will work.

    Sub Macro1()
        For Each cell In Range("AD1:AD" & Cells(Rows.Count, "AD").End(xlUp).Row)
            If IsDate(cell.Value) Then
                If cell.Value = Date - 1 Then
                   MsgBox "date is correct"
                Else
                   MsgBox "date is incorrect"
                End If
            End If
        Next
    End Sub

  3. #3
    Registered User
    Join Date
    01-09-2012
    Location
    here
    MS-Off Ver
    Excel 2003
    Posts
    68

    Re: Check column for yesterday's date

    works great but is it possbile to give me msg once and not for each cell it checks in that column. i just want to know if the date is in the column at all and if it is jsut send me a msg once whether it is or isn't

  4. #4
    Forum Contributor
    Join Date
    10-08-2010
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    386

    Re: Check column for yesterday's date

    Try this:

    Sub Find_First()
        Dim FindString As String
        Dim Rng As Range
        FindString = date - 1
            With Sheets("Sheet1").Range("A:A")
                Set Rng = .Find(What:=FindString, _
                                After:=.Cells(.Cells.Count), _
                                LookIn:=xlValues, _
                                LookAt:=xlWhole, _
                                SearchOrder:=xlByRows, _
                                SearchDirection:=xlNext, _
                                MatchCase:=False)
            End With
    
    If rng is nothing then
    msgbox "Date is incorrect."
    else
    msgbox "Date is correct."
    end if
    
    End Sub
    Last edited by GaidenFocus; 07-31-2012 at 04:23 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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