ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Weekday Function Returns Wrong Number (https://www.excelbanter.com/excel-programming/373166-weekday-function-returns-wrong-number.html)

Thomas M.

Weekday Function Returns Wrong Number
 
Excel 2003

I created the following very simple subroutine as a test.

Sub CheckDay()
MsgBox Weekday(Today)
End Sub

The message box displays the number 7. Unfortunately, today is Monday and
the message box should display the number 2. I've verified that my system
time and date are correct. It seems to me that I've run into this before
and that the fix is easy, but I'm just drawing a complete blank and searches
of the on-line help have been fruitless. Can anyone tell me how to make
this simple subroutine return the correct number for the day of the week?

--Tom



Ron de Bruin

Weekday Function Returns Wrong Number
 
Use Date instead of Today

--
Regards Ron de Bruin
http://www.rondebruin.nl



"Thomas M." wrote in message ...
Excel 2003

I created the following very simple subroutine as a test.

Sub CheckDay()
MsgBox Weekday(Today)
End Sub

The message box displays the number 7. Unfortunately, today is Monday and the message box should display the number 2. I've
verified that my system time and date are correct. It seems to me that I've run into this before and that the fix is easy, but
I'm just drawing a complete blank and searches of the on-line help have been fruitless. Can anyone tell me how to make this
simple subroutine return the correct number for the day of the week?

--Tom




Carim

Weekday Function Returns Wrong Number
 
Hi Tom,

Take a look at Chip's excellent summary ...

http://www.cpearson.com/excel/weeknum.htm

HTH
Cheers
Carim


Ron Rosenfeld

Weekday Function Returns Wrong Number
 
On Mon, 18 Sep 2006 13:29:09 -0600, "Thomas M."
wrote:

Excel 2003

I created the following very simple subroutine as a test.

Sub CheckDay()
MsgBox Weekday(Today)
End Sub

The message box displays the number 7. Unfortunately, today is Monday and
the message box should display the number 2. I've verified that my system
time and date are correct. It seems to me that I've run into this before
and that the fix is easy, but I'm just drawing a complete blank and searches
of the on-line help have been fruitless. Can anyone tell me how to make
this simple subroutine return the correct number for the day of the week?

--Tom


In addition to what others have written, "Today" is not a valid keyword in VBA.
So it evaluates to Zero in the expression in your subroutine.

The ZEROth day of the calendar, in VBA, is 30 Dec 1899 which is a Saturday.


--ron

Joergen Bondesen

Weekday Function Returns Wrong Number
 
Hi Thomas

Sub CheckDay()
MsgBox Weekday(Now, vbMonday)
End Sub


Syntax

Weekday(date, [firstdayofweek])
--
Best Regards
Joergen Bondesen



"Thomas M." wrote in message
...
Excel 2003

I created the following very simple subroutine as a test.

Sub CheckDay()
MsgBox Weekday(Today)
End Sub

The message box displays the number 7. Unfortunately, today is Monday and
the message box should display the number 2. I've verified that my system
time and date are correct. It seems to me that I've run into this before
and that the fix is easy, but I'm just drawing a complete blank and
searches of the on-line help have been fruitless. Can anyone tell me how
to make this simple subroutine return the correct number for the day of
the week?

--Tom




Joergen Bondesen

Weekday Function Returns Wrong Number
 
Hi Thomas

Sorry, if 2

Sub CheckDay()
MsgBox Weekday(Now, vbSunday)
End Sub

--
Best Regards
Joergen Bondesen


"Joergen Bondesen" wrote in message
...
Hi Thomas

Sub CheckDay()
MsgBox Weekday(Now, vbMonday)
End Sub


Syntax

Weekday(date, [firstdayofweek])
--
Best Regards
Joergen Bondesen



"Thomas M." wrote in message
...
Excel 2003

I created the following very simple subroutine as a test.

Sub CheckDay()
MsgBox Weekday(Today)
End Sub

The message box displays the number 7. Unfortunately, today is Monday
and the message box should display the number 2. I've verified that my
system time and date are correct. It seems to me that I've run into this
before and that the fix is easy, but I'm just drawing a complete blank
and searches of the on-line help have been fruitless. Can anyone tell me
how to make this simple subroutine return the correct number for the day
of the week?

--Tom






Thomas M.

Weekday Function Returns Wrong Number
 
DOH! I knew it was something easy, but I just couldn't pull it out of the
ol' memory banks. Thanks for your help!

--Tom

"Ron de Bruin" wrote in message
...
Use Date instead of Today

--
Regards Ron de Bruin
http://www.rondebruin.nl



"Thomas M." wrote in message
...
Excel 2003

I created the following very simple subroutine as a test.

Sub CheckDay()
MsgBox Weekday(Today)
End Sub

The message box displays the number 7. Unfortunately, today is Monday
and the message box should display the number 2. I've verified that my
system time and date are correct. It seems to me that I've run into this
before and that the fix is easy, but I'm just drawing a complete blank
and searches of the on-line help have been fruitless. Can anyone tell me
how to make this simple subroutine return the correct number for the day
of the week?

--Tom






Thomas M.

Weekday Function Returns Wrong Number
 
Thanks for the link. It seems like I always kind of stumble over this stuff
because I just don't work with it that often. In fact, I've taken to
keeping files in an Examples folder that I refer back to, and I know that I
have this one stored in that folder, but I don't have access to those files
at the moment.

--Tom

"Carim" wrote in message
oups.com...
Hi Tom,

Take a look at Chip's excellent summary ...

http://www.cpearson.com/excel/weeknum.htm

HTH
Cheers
Carim





All times are GMT +1. The time now is 12:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com