Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Something wrong with undefined functions.


Hello.

I have this "workbook_open" sub that looks like this.

Code:
--------------------
Private Sub Workbook_Open()
Application.CalculateFull
If (Weekday(Today()) = 6) Then
[Sheets("Stora lev problem").Range("E3") = TODAY() + 3]
Else
[Sheets("Stora lev problem").Range("E3") = TODAY() + 1]
End If

End Sub
--------------------


I get an error that TODAY() is not defined when I open the workbook.
Why? Isn't TODAY() a general function in excel that should work
automaticaly?

Can someone please give me a hint?
/Anders


--
a94andwi
------------------------------------------------------------------------
a94andwi's Profile: http://www.excelforum.com/member.php...o&userid=21077
View this thread: http://www.excelforum.com/showthread...hreadid=520475

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Something wrong with undefined functions.

Hi Anders,

Try:

'=============
Private Sub Workbook_Open()
Application.CalculateFull
If (Weekday(Date) = 6) Then
Sheets("Stora lev problem").Range("E3") = Date + 3
Else
Sheets("Stora lev problem").Range("E3") = Date + 1
End If

End Sub
'<<=============


---
Regards,
Norman



"a94andwi" wrote in
message ...

Hello.

I have this "workbook_open" sub that looks like this.

Code:
--------------------
Private Sub Workbook_Open()
Application.CalculateFull
If (Weekday(Today()) = 6) Then
[Sheets("Stora lev problem").Range("E3") = TODAY() + 3]
Else
[Sheets("Stora lev problem").Range("E3") = TODAY() + 1]
End If

End Sub
--------------------


I get an error that TODAY() is not defined when I open the workbook.
Why? Isn't TODAY() a general function in excel that should work
automaticaly?

Can someone please give me a hint?
/Anders


--
a94andwi
------------------------------------------------------------------------
a94andwi's Profile:
http://www.excelforum.com/member.php...o&userid=21077
View this thread: http://www.excelforum.com/showthread...hreadid=520475



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Something wrong with undefined functions.


Hello

I tried your code and it seem to work but there are still an error I
can't explain.

Code:
--------------------
If (Weekday(Date = 6)) Then
Sheets("Stora lev problem").Range("E3") = Weekday(Date + 3)
Sheets("Stora lev problem").Range("L4") = Weekday(Date)
Else
Sheets("Stora lev problem").Range("E3") = Weekday(Date + 1)
Sheets("Stora lev problem").Range("L4") = Weekday(Date)

End If


If (Weekday(Date = 6)) Then

Sheets("Stora lev problem").Range("F3") = Weekday(Date + 4)
Sheets("Stora lev problem").Range("L5") = Weekday(Date)

ElseIf (Weekday(Date = 5)) Then
Sheets("Stora lev problem").Range("F3") = Weekday(Date + 3)
Sheets("Stora lev problem").Range("L5") = Weekday(Date)

Else

Sheets("Stora lev problem").Range("F3") = Weekday(Date + 2)
Sheets("Stora lev problem").Range("L5") = Weekday(Date)

End If



--------------------


I added another field and watched what would happen.
In cell E3 it writes 1900-01-01 (The first IF-statement) and 02 in cell
F3 (The second if-statement). Do you know why does the same function
return two different results?

Do you have any idea?

/Anders


--
a94andwi
------------------------------------------------------------------------
a94andwi's Profile: http://www.excelforum.com/member.php...o&userid=21077
View this thread: http://www.excelforum.com/showthread...hreadid=520475

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Something wrong with undefined functions.

Anders,
Does this help?

Sub Problem()

If Weekday(Date) = 6 Then
Sheets("Stora lev problem").Range("E3") = Weekday(Date + 3)
Sheets("Stora lev problem").Range("L4") = Weekday(Date)
Else
Sheets("Stora lev problem").Range("E3") = Weekday(Date + 1)
Sheets("Stora lev problem").Range("L4") = Weekday(Date)
End If

If Weekday(Date) = 6 Then
Sheets("Stora lev problem").Range("F3") = Weekday(Date + 4)
Sheets("Stora lev problem").Range("L5") = Weekday(Date)
ElseIf Weekday(Date) = 5 Then
Sheets("Stora lev problem").Range("F3") = Weekday(Date + 3)
Sheets("Stora lev problem").Range("L5") = Weekday(Date)
Else
Sheets("Stora lev problem").Range("F3") = Weekday(Date + 2)
Sheets("Stora lev problem").Range("L5") = Weekday(Date)
End If

End Sub

I added brackets around the date functions in your IF statements. It DOES
produce a different result, just not sure if it's what you're looking for.

Regards

Pete
"a94andwi" wrote:


Hello

I tried your code and it seem to work but there are still an error I
can't explain.

Code:
--------------------
If (Weekday(Date = 6)) Then
Sheets("Stora lev problem").Range("E3") = Weekday(Date + 3)
Sheets("Stora lev problem").Range("L4") = Weekday(Date)
Else
Sheets("Stora lev problem").Range("E3") = Weekday(Date + 1)
Sheets("Stora lev problem").Range("L4") = Weekday(Date)

End If


If (Weekday(Date = 6)) Then

Sheets("Stora lev problem").Range("F3") = Weekday(Date + 4)
Sheets("Stora lev problem").Range("L5") = Weekday(Date)

ElseIf (Weekday(Date = 5)) Then
Sheets("Stora lev problem").Range("F3") = Weekday(Date + 3)
Sheets("Stora lev problem").Range("L5") = Weekday(Date)

Else

Sheets("Stora lev problem").Range("F3") = Weekday(Date + 2)
Sheets("Stora lev problem").Range("L5") = Weekday(Date)

End If



--------------------


I added another field and watched what would happen.
In cell E3 it writes 1900-01-01 (The first IF-statement) and 02 in cell
F3 (The second if-statement). Do you know why does the same function
return two different results?

Do you have any idea?

/Anders


--
a94andwi
------------------------------------------------------------------------
a94andwi's Profile: http://www.excelforum.com/member.php...o&userid=21077
View this thread: http://www.excelforum.com/showthread...hreadid=520475


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Functions Undefined James O. Thompson Excel Worksheet Functions 2 January 20th 09 10:41 PM
Undefined function q Excel Programming 4 February 25th 06 03:47 AM
Undefined function q Excel Programming 3 February 24th 06 09:22 PM
How wrong can you be with your NPV and MIRR functions in EXCel opieandy Excel Worksheet Functions 3 June 27th 05 10:15 PM
2147217900 undefined function jinsong Excel Programming 1 June 29th 04 04:23 PM


All times are GMT +1. The time now is 08:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"