PC Review


Reply
Thread Tools Rate Thread

Application-defined or object-defined error

 
 
Ayo
Guest
Posts: n/a
 
      24th Nov 2009
I need help with this error. I get the error on line
"ws.Range("E7").Value = mondaysDate(Weekday(Date)) - 7"
The function run fine, its just that the erroe comes up when control is
returned to the subroutine. And I don't know what the problem is. Any help
will be appreciated.
Thanks.

Private Sub Workbook_Open()
Dim ws As Worksheet
Const PWORD As String = "Ayo"
Application.ScreenUpdating = False

If Me.Name = "Northeast AAV Project Outlook_ver2.xls" Then
If Weekday(Date) = 2 Then
For Each ws In Worksheets
If ws.Name <> "BO Download" Then
ws.Visible = True
ws.Range("E7").Value = Date - 7
ws.Range("F7").Value = Date
ws.Range("J6").Value = Date
End If
Next
ElseIf Weekday(Date) <> 2 Then
For Each ws In Worksheets
If ws.Name <> "BO Download" Then
ws.Visible = True
ws.Range("F7").Value = Date
ws.Range("E7").Value = mondaysDate(Weekday(Date)) - 7
ws.Range("J6").Value = mondaysDate(Weekday(Date))
End If
Next
End If
Else
Exit Sub
End If
Application.ScreenUpdating = True
End Sub

Function mondaysDate(dayNumber) As Date
Select Case dayNumber
Case 1
mondayDate = Date - 6
Case 3
mondayDate = Date - 1
Case 4
mondayDate = Date - 2
Case 5
mondayDate = Date - 3
Case 6
mondayDate = Date - 4
Case 7
mondayDate = Date - 5
End Select
End Function

 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      24th Nov 2009
Ayo

--Within the function you have mentioned 'mondayDate' and not 'mondayDates'.
The 's' is missing. Use the Option Explicit statement on top of your module
to avoid such errors

--To find previous mondays date you can try the below
MsgBox Date - (Weekday(Date)) - 5

If this post helps click Yes
---------------
Jacob Skaria


"Ayo" wrote:

> I need help with this error. I get the error on line
> "ws.Range("E7").Value = mondaysDate(Weekday(Date)) - 7"
> The function run fine, its just that the erroe comes up when control is
> returned to the subroutine. And I don't know what the problem is. Any help
> will be appreciated.
> Thanks.
>
> Private Sub Workbook_Open()
> Dim ws As Worksheet
> Const PWORD As String = "Ayo"
> Application.ScreenUpdating = False
>
> If Me.Name = "Northeast AAV Project Outlook_ver2.xls" Then
> If Weekday(Date) = 2 Then
> For Each ws In Worksheets
> If ws.Name <> "BO Download" Then
> ws.Visible = True
> ws.Range("E7").Value = Date - 7
> ws.Range("F7").Value = Date
> ws.Range("J6").Value = Date
> End If
> Next
> ElseIf Weekday(Date) <> 2 Then
> For Each ws In Worksheets
> If ws.Name <> "BO Download" Then
> ws.Visible = True
> ws.Range("F7").Value = Date
> ws.Range("E7").Value = mondaysDate(Weekday(Date)) - 7
> ws.Range("J6").Value = mondaysDate(Weekday(Date))
> End If
> Next
> End If
> Else
> Exit Sub
> End If
> Application.ScreenUpdating = True
> End Sub
>
> Function mondaysDate(dayNumber) As Date
> Select Case dayNumber
> Case 1
> mondayDate = Date - 6
> Case 3
> mondayDate = Date - 1
> Case 4
> mondayDate = Date - 2
> Case 5
> mondayDate = Date - 3
> Case 6
> mondayDate = Date - 4
> Case 7
> mondayDate = Date - 5
> End Select
> End Function
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding names to a cell - application-defined or object-defined error Chris Microsoft Excel Discussion 1 20th Sep 2007 08:31 PM
Application-Defined or object defined error 1004 When ran on exel97 but not 2003 bornweb Microsoft Excel Programming 0 17th Feb 2007 11:30 PM
Copying A Range of Cells From one Sheet to Another - Error Application Defined or Object Defined Matt Microsoft Excel Programming 3 25th Jul 2006 01:13 AM
RE: Runtime error 1004- application defined or object defined erro =?Utf-8?B?Tm92aWNl?= Microsoft Excel Programming 0 6th Feb 2006 09:34 PM
RE: Runtime error 1004- application defined or object defined erro =?Utf-8?B?Tm92aWNl?= Microsoft Excel Programming 1 6th Feb 2006 09:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:48 AM.