Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

excel vba [code] Option Explicit Function check15days(postDate As Long, dueDate

ID: 3692396 • Letter: E

Question

excel vba

[code]

Option Explicit

Function check15days(postDate As Long, dueDate As Long)

    Dim calcDate As Long

   calcDate = (postDate - dueDate)
   
    If (IsEmpty(postDate) = True Or IsEmpty(dueDate) = True) Then
        check15days = "no dates found"


        ElseIf (calcDate) < 15 Then
            check15days = "good"
       
        Else
            check15days = (calcDate) & " dpd"
    End If
   
End Function

[/code]

...the code is not executing the first if statement when the selected cells have no data in it.

Thank you in advance.

*********************************************************

*********************************************************

update:

i figured it out. here is the updated code:

[code]

Option Explicit

Function check15days(postDate As Range, dueDate As Range)
   
    Dim calcDate As Long
   
    If (IsEmpty(postDate.Value)) Or (IsEmpty(dueDate.Value)) Then
        check15days = "no dates found"
   
    calcDate = (postDate - dueDate)

        ElseIf (calcDate) < 15 Then
            check15days = "good"

        Else
            check15days = (calcDate) & " dpd"
    End If
   
End Function

[/code]

Explanation / Answer

Option Explicit
Function check15days(postDate As Range, dueDate As Range)
   Dim calcDate As Long
   If (IsEmpty(postDate.Value)) Or (IsEmpty(dueDate.Value)) Then
       check15days = "no dates found"
       calcDate = (postDate - dueDate)
   ElseIf (calcDate) < 15 Then
       check15days = "good"
   Else
       check15days = (calcDate) & " dpd"
End If
End Function