compile error sub or function not defined

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
563
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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.
 
Upvote 0
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
 
Upvote 0
Thank you all for your help. I forgot about using date. When I did use it, it worked.
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,387
Messages
6,119,222
Members
448,877
Latest member
gb24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top