+ Reply to Thread
Results 1 to 2 of 2

variable date not working with date add?

Hybrid View

  1. #1
    Registered User
    Join Date
    06-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    7

    variable date not working with date add?

    Hi everyone,

    I have an array of dates and I'm trying to search for dates that are more than 2 years old but I can get the dateadd to work with the search loop. can anybody tell me why the code isn't working please.

     
    
    Private Sub Workbook_Open()
        With Sheets("Sheet1")
            Dim due As Range
            Dim i As Long, j As Long
            Set due = Range("H24:AJ68")
            
            For i = 1 To due.Rows.Count
                For j = 1 To due.Columns.Count
                    If DateAdd("YYYY", 2, due.Cells(i, j).Value) < Date Then
                        due.Cells(i, j).Font.ColorIndex = 3
                    Else
                        due.Cells(i, j).Font.ColorIndex = 1
                    End If
                Next j
            Next i
        End With
    End Sub
    Thanks
    Last edited by Leith Ross; 01-26-2013 at 04:11 PM. Reason: Added Code tags

  2. #2
    Registered User
    Join Date
    06-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: variable date not working with date add?

    Fixed it myself with
    If due.Cells(i, j).Value < (Date - 730) Then

    cheers

+ 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