Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Problems with code

The added If statement at the beginning will test for the
current date being Monday, If it is, it will then check
Cell M2 for the previous Friday's date, If it is, it will
Copy the range and then clear it. If it is not Monday, it
will then check to see if it is a day from Tuesday thru
Thrusday and do the copy and clear. If the criteria is not
met in either part of the If...EsleIf statement, it will not
do the copy and clear.


Sheets("Cus Futures").Select
If Format(Date, "w") = "2" And Range("M2") = Date - 3 Then
Range(" H9:I50").Copy Range("D9:E50")
Range("F9:I50").ClearContents
Range("M2") = Date
ElseIf Weekday(Date, vbMonday) < 6 And Range("M2") = _
(Date - 1) Then
Range(" H9:I50").Copy Range("D9:E50")
Range("F9:I50").ClearContents
Range("M2") = Date
End If

"chrisnsmith" wrote:

I have asked a similar question before but I realized I have more paramaters
I need to cover. I have to save and email my workbook daily and it is
sometimes necessary to open the saved workbooks to verify the info I email.

I have three problems I need to solve.

1. I need this to run only on weekdays.
2. My code ('M2") = (Date - 1) doesn"t take into account weekends. So it
won't work on Mondays. I need to correct this.
3. I don't want this code to run when I open an older saved workbook.

Can anyone help?

Sheets("Cus Futures").Select
If Weekday(Date, vbMonday) < 6 And Range("M2") = (Date - 1) Then
Range(" H9:I50").Copy Range("D9:E50")
Range("F9:I50").ClearContents
Range("M2") = Date
End If

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Problems with code

There is a problem with the Elself statement. When I try to run the code
I get a message that says sub or function is not defined and the word (Range)
is highlighted. What's wrong, and how do I fix it?

"JLGWhiz" wrote:

The added If statement at the beginning will test for the
current date being Monday, If it is, it will then check
Cell M2 for the previous Friday's date, If it is, it will
Copy the range and then clear it. If it is not Monday, it
will then check to see if it is a day from Tuesday thru
Thrusday and do the copy and clear. If the criteria is not
met in either part of the If...EsleIf statement, it will not
do the copy and clear.


Sheets("Cus Futures").Select
If Format(Date, "w") = "2" And Range("M2") = Date - 3 Then
Range(" H9:I50").Copy Range("D9:E50")
Range("F9:I50").ClearContents
Range("M2") = Date
ElseIf Weekday(Date, vbMonday) < 6 And Range("M2") = _
(Date - 1) Then
Range(" H9:I50").Copy Range("D9:E50")
Range("F9:I50").ClearContents
Range("M2") = Date
End If

"chrisnsmith" wrote:

I have asked a similar question before but I realized I have more paramaters
I need to cover. I have to save and email my workbook daily and it is
sometimes necessary to open the saved workbooks to verify the info I email.

I have three problems I need to solve.

1. I need this to run only on weekdays.
2. My code ('M2") = (Date - 1) doesn"t take into account weekends. So it
won't work on Mondays. I need to correct this.
3. I don't want this code to run when I open an older saved workbook.

Can anyone help?

Sheets("Cus Futures").Select
If Weekday(Date, vbMonday) < 6 And Range("M2") = (Date - 1) Then
Range(" H9:I50").Copy Range("D9:E50")
Range("F9:I50").ClearContents
Range("M2") = Date
End If

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Problems with code

Not sure what is causing it to error on your system. It runs fine on mine.
Check for typos in the spelling, missing Quote marks, etc.

"chrisnsmith" wrote:

There is a problem with the Elself statement. When I try to run the code
I get a message that says sub or function is not defined and the word (Range)
is highlighted. What's wrong, and how do I fix it?

"JLGWhiz" wrote:

The added If statement at the beginning will test for the
current date being Monday, If it is, it will then check
Cell M2 for the previous Friday's date, If it is, it will
Copy the range and then clear it. If it is not Monday, it
will then check to see if it is a day from Tuesday thru
Thrusday and do the copy and clear. If the criteria is not
met in either part of the If...EsleIf statement, it will not
do the copy and clear.


Sheets("Cus Futures").Select
If Format(Date, "w") = "2" And Range("M2") = Date - 3 Then
Range(" H9:I50").Copy Range("D9:E50")
Range("F9:I50").ClearContents
Range("M2") = Date
ElseIf Weekday(Date, vbMonday) < 6 And Range("M2") = _
(Date - 1) Then
Range(" H9:I50").Copy Range("D9:E50")
Range("F9:I50").ClearContents
Range("M2") = Date
End If

"chrisnsmith" wrote:

I have asked a similar question before but I realized I have more paramaters
I need to cover. I have to save and email my workbook daily and it is
sometimes necessary to open the saved workbooks to verify the info I email.

I have three problems I need to solve.

1. I need this to run only on weekdays.
2. My code ('M2") = (Date - 1) doesn"t take into account weekends. So it
won't work on Mondays. I need to correct this.
3. I don't want this code to run when I open an older saved workbook.

Can anyone help?

Sheets("Cus Futures").Select
If Weekday(Date, vbMonday) < 6 And Range("M2") = (Date - 1) Then
Range(" H9:I50").Copy Range("D9:E50")
Range("F9:I50").ClearContents
Range("M2") = Date
End If

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Problems with code

Thanks, I did and found that in the first Elseif statement I left out a
parenthesis.

"JLGWhiz" wrote:

Not sure what is causing it to error on your system. It runs fine on mine.
Check for typos in the spelling, missing Quote marks, etc.

"chrisnsmith" wrote:

There is a problem with the Elself statement. When I try to run the code
I get a message that says sub or function is not defined and the word (Range)
is highlighted. What's wrong, and how do I fix it?

"JLGWhiz" wrote:

The added If statement at the beginning will test for the
current date being Monday, If it is, it will then check
Cell M2 for the previous Friday's date, If it is, it will
Copy the range and then clear it. If it is not Monday, it
will then check to see if it is a day from Tuesday thru
Thrusday and do the copy and clear. If the criteria is not
met in either part of the If...EsleIf statement, it will not
do the copy and clear.


Sheets("Cus Futures").Select
If Format(Date, "w") = "2" And Range("M2") = Date - 3 Then
Range(" H9:I50").Copy Range("D9:E50")
Range("F9:I50").ClearContents
Range("M2") = Date
ElseIf Weekday(Date, vbMonday) < 6 And Range("M2") = _
(Date - 1) Then
Range(" H9:I50").Copy Range("D9:E50")
Range("F9:I50").ClearContents
Range("M2") = Date
End If

"chrisnsmith" wrote:

I have asked a similar question before but I realized I have more paramaters
I need to cover. I have to save and email my workbook daily and it is
sometimes necessary to open the saved workbooks to verify the info I email.

I have three problems I need to solve.

1. I need this to run only on weekdays.
2. My code ('M2") = (Date - 1) doesn"t take into account weekends. So it
won't work on Mondays. I need to correct this.
3. I don't want this code to run when I open an older saved workbook.

Can anyone help?

Sheets("Cus Futures").Select
If Weekday(Date, vbMonday) < 6 And Range("M2") = (Date - 1) Then
Range(" H9:I50").Copy Range("D9:E50")
Range("F9:I50").ClearContents
Range("M2") = Date
End If

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
Code Problems Leon Excel Programming 1 August 3rd 07 12:28 PM
Code problems [email protected] Excel Programming 0 April 5th 06 10:43 PM
Problems with code tac Excel Programming 2 March 10th 06 03:12 AM
Problems merging an excel file due to code or file problems? Cindy M -WordMVP- Excel Programming 0 September 14th 04 02:58 PM
VBA Code problems! Simon Lloyd[_463_] Excel Programming 5 May 24th 04 10:21 PM


All times are GMT +1. The time now is 09:05 AM.

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

About Us

"It's about Microsoft Excel"