compile error sub or function not defined

Pookiemeister

Board Regular
Joined
Nov 26, 2015
Messages
240
Office Version
365, 2010
I changed the date on my computer to test the following code so the current date would be a date that falls on a Monday.
If the current day of the week is a Monday, display the current date in Sheet1.Range("B1")
The error message occurs on the following line of code the word "today" is highlighted in blue:

Code:
Sheet1.Range("B1") = today()

The rest of the code:
Code:
Sub Weekdays()

    If weekday(Now()) = vbMonday Then
        MsgBox "Monday"
        Sheet1.Range("B1") = today()
    Else
        MsgBox Format$(Now, "dddd")
        Debug.Print Format$(Now, "dddd")
    End If


End Sub
Thank You
 

Some videos you may like

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

MoshiM

Active Member
Joined
Jan 31, 2018
Messages
349
I changed the date on my computer to test the following code so the current date would be a date that falls on a Monday.
If the current day of the week is a Monday, display the current date in Sheet1.Range("B1")
The error message occurs on the following line of code the word "today" is highlighted in blue:

Code:
Sheet1.Range("B1") = today()
Today isn't a function. Change it to date.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
40,524
Office Version
365
Platform
Windows
Change it to
Rich (BB code):
Sub Weekdays()

    If Weekday(Date) = vbMonday Then
        MsgBox "Monday"
        Sheet1.Range("B1") = Date
    Else
        MsgBox Format$(Date, "dddd")
        Debug.Print Format$(Date, "dddd")
    End If


End Sub
 

Pookiemeister

Board Regular
Joined
Nov 26, 2015
Messages
240
Office Version
365, 2010
Thank you all for your help. I forgot about using date. When I did use it, it worked.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
40,524
Office Version
365
Platform
Windows
Glad we could help & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,098,858
Messages
5,465,106
Members
406,412
Latest member
superjoejoe

This Week's Hot Topics

Top