'Subtract the date from each cell in a column, skip cells that have string values
I have an Excel sheet of expiration dates. Some rows lack an expiration date so I chose to fill those cells with the string “NO DATA”.
I want to loop through all the cells and find how many days the user has before the expiration date passes.
Then I want to send an email with the list of cells whose expiration dates will expire within two weeks.
I am stuck at the looping part so I just want to get at least that done.
Column A has the truck Id and Column D has the expiration dates for one document. (I have versions but I want to focus on just one first.)
Column B to C is full of values. They just aren’t worth mentioning at this moment—at least I think.
The code I created results in a type mismatch which makes sense since the cells in Column D aren't the same data type.
I fixed small mistakes but it still doesn't work.
Sub Run_Button1()
Dim mydate1 As Range
Dim datetoday1 As Date
Dim dateDif As Long
datetoday1 = Now
For Each mydate1 In Sheets("Sheet1").Range("A1:A25").Cells
    If IsDate(mydate1.Value) Then
        dateDif = DateDiff("d", mydate1.Value, Date)
        If dateDif > 1 And dateDif < 14 Then
            'This code will be added later.this code will send emails
        End If
    End If
Next mydate1
End Sub
							
						Solution 1:[1]
From comments above:
Sub Run_Button1()
    Dim c As Range, v
    Dim dateDif As Long
    
    For Each c In Sheets("Sheet1").Range("A1:A25").Cells
        v = c.EntireRow.Columns("D").Value 'read from date column
        If IsDate(v) Then
            dateDif = DateDiff("d", cdate(v), Date)
            If dateDif > 1 And dateDif < 14 Then
    
            End If
        End If
    Next c
End Sub
    					Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|---|
| Solution 1 | Tim Williams | 
