StackUser2014
StackUser2014

Reputation: 51

If statement for current date

I am using an ElseIf statement and the systems date to create an output.

Here is my code so far:

Dim dateToday As Date
Dim fifth As Integer
Dim fifthteenth As Integer
Dim twentyEighth As Integer
Dim thirtieth As Integer

dateToday = Today
fifth = 5
fifthteenth = 17 'this is changed to todays date for testing otherwise its 15
twentyEighth = 28
thirtieth = 30

If fifth = dateToday Then
    MsgBox ("Today is the fifth")
ElseIf fifthteenth = dateToday Then
    MsgBox ("Today is the fifthteenth")
ElseIf twentyEighth = dateToday Then
    MsgBox ("Today is the 28th")
ElseIf thirtieth = dateToday Then
    MsgBox ("Today is the 30th")
Else
    MsgBox ("You do not need to do anything yet")
End If

It is going straight to the end and produces the last message box.

Upvotes: 0

Views: 758

Answers (1)

Rory
Rory

Reputation: 34075

Today is a worksheet function, not a VBA function - you want Date:

dateToday = Date

then you actually want to test against Day(dateToday) not just dateToday

Upvotes: 1

Related Questions