Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
I'm having a problem with the If and Elseif functions.
When I enter the following everything works fine. If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ ..Cells(13, 2).Value = Date - 3 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents ..Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents ..Range("M2") = Date End With ElseIf Weekday(Date,vbMonday) = 2 < 7 And Worksheets("Cus Futures") _ ..Cells(1, 1).Value = Date -1 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents ..Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents ..Range("M2") = Date End With I only list two worksheets for simplicities sake, however I have 31 worksheets that need to be updated daily. So I have placed all worksheets to update in a module called UpdateForms and did the following. I changed my If statement to; If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ ..Cells (1, 1). Value = Date -3 Then Call UpdateForms End if When I run this I get a message End If without a block If. I changed both my If statement and Elseif statement to: If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ ..Cells (1, 1). Value = Date -3 Then Call UpdateForms Elseif Weekday(Date, vbMonday) =2 < 7 And Worksheets("Cus Futures") _ ..Cells (1, 1).Value = Date - 1 Then Call UpdateForms When I run this code I get a similar message Else without an If. What am I doing wrong and how do I correct it? |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi
Either use: If A1= B1 Then call MySub or if A1=B1 then Call MySub else 'Else and ElseIf is optional 'Do whatEver End if Your statement should look like: If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ ..Cells (1, 1). Value = Date -3 Then Call UpdateForms Elseif Weekday(Date, vbMonday) =2 < 7 And Worksheets("Cus Futures") _ ..Cells (1, 1).Value = Date - 1 Then Call UpdateForms End If Regards, Per "chrisnsmith" skrev i meddelelsen ... I'm having a problem with the If and Elseif functions. When I enter the following everything works fine. If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells(13, 2).Value = Date - 3 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ElseIf Weekday(Date,vbMonday) = 2 < 7 And Worksheets("Cus Futures") _ .Cells(1, 1).Value = Date -1 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With I only list two worksheets for simplicities sake, however I have 31 worksheets that need to be updated daily. So I have placed all worksheets to update in a module called UpdateForms and did the following. I changed my If statement to; If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells (1, 1). Value = Date -3 Then Call UpdateForms End if When I run this I get a message End If without a block If. I changed both my If statement and Elseif statement to: If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells (1, 1). Value = Date -3 Then Call UpdateForms Elseif Weekday(Date, vbMonday) =2 < 7 And Worksheets("Cus Futures") _ .Cells (1, 1).Value = Date - 1 Then Call UpdateForms When I run this code I get a similar message Else without an If. What am I doing wrong and how do I correct it? |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() If Weekday(Date, vbMonday) = 1 And _ Worksheets("Cus Futures").Cells (1, 1). Value = Date -3 Then Call UpdateForms Elseif Weekday(Date, vbMonday) =2 < 7 And _ Worksheets("Cus Futures").Cells (1, 1).Value = Date - 1 Then Call UpdateForms 'etc. -- __________________________________ HTH Bob "chrisnsmith" wrote in message ... I'm having a problem with the If and Elseif functions. When I enter the following everything works fine. If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells(13, 2).Value = Date - 3 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ElseIf Weekday(Date,vbMonday) = 2 < 7 And Worksheets("Cus Futures") _ .Cells(1, 1).Value = Date -1 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With I only list two worksheets for simplicities sake, however I have 31 worksheets that need to be updated daily. So I have placed all worksheets to update in a module called UpdateForms and did the following. I changed my If statement to; If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells (1, 1). Value = Date -3 Then Call UpdateForms End if When I run this I get a message End If without a block If. I changed both my If statement and Elseif statement to: If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells (1, 1). Value = Date -3 Then Call UpdateForms Elseif Weekday(Date, vbMonday) =2 < 7 And Worksheets("Cus Futures") _ .Cells (1, 1).Value = Date - 1 Then Call UpdateForms When I run this code I get a similar message Else without an If. What am I doing wrong and how do I correct it? |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Something is wrong with the first part of your ElseIf statement, namely this
part... Weekday(Date,vbMonday) = 2 < 7 What is "equal 2, less than 7" supposed to mean? What test are you trying to perform? -- Rick (MVP - Excel) "chrisnsmith" wrote in message ... I'm having a problem with the If and Elseif functions. When I enter the following everything works fine. If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells(13, 2).Value = Date - 3 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ElseIf Weekday(Date,vbMonday) = 2 < 7 And Worksheets("Cus Futures") _ .Cells(1, 1).Value = Date -1 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With I only list two worksheets for simplicities sake, however I have 31 worksheets that need to be updated daily. So I have placed all worksheets to update in a module called UpdateForms and did the following. I changed my If statement to; If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells (1, 1). Value = Date -3 Then Call UpdateForms End if When I run this I get a message End If without a block If. I changed both my If statement and Elseif statement to: If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells (1, 1). Value = Date -3 Then Call UpdateForms Elseif Weekday(Date, vbMonday) =2 < 7 And Worksheets("Cus Futures") _ .Cells (1, 1).Value = Date - 1 Then Call UpdateForms When I run this code I get a similar message Else without an If. What am I doing wrong and how do I correct it? |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
If it is Tuesday thru Friday
"Rick Rothstein" wrote: Something is wrong with the first part of your ElseIf statement, namely this part... Weekday(Date,vbMonday) = 2 < 7 What is "equal 2, less than 7" supposed to mean? What test are you trying to perform? -- Rick (MVP - Excel) "chrisnsmith" wrote in message ... I'm having a problem with the If and Elseif functions. When I enter the following everything works fine. If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells(13, 2).Value = Date - 3 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ElseIf Weekday(Date,vbMonday) = 2 < 7 And Worksheets("Cus Futures") _ .Cells(1, 1).Value = Date -1 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With I only list two worksheets for simplicities sake, however I have 31 worksheets that need to be updated daily. So I have placed all worksheets to update in a module called UpdateForms and did the following. I changed my If statement to; If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells (1, 1). Value = Date -3 Then Call UpdateForms End if When I run this I get a message End If without a block If. I changed both my If statement and Elseif statement to: If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells (1, 1). Value = Date -3 Then Call UpdateForms Elseif Weekday(Date, vbMonday) =2 < 7 And Worksheets("Cus Futures") _ .Cells (1, 1).Value = Date - 1 Then Call UpdateForms When I run this code I get a similar message Else without an If. What am I doing wrong and how do I correct it? |
#6
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
You can't do it that way... you can't do a double test in a single logical
expression. However, VB's Weekday function calculate starting with any day of the week, so let's start with Tuesday. Give this ElseIf statement a try... ElseIf Weekday(Date, vbTuesday) < 5 And Worksheets("Cus Futures").Cells(1, 1).Value = Date -1 Then -- Rick (MVP - Excel) "chrisnsmith" wrote in message ... If it is Tuesday thru Friday "Rick Rothstein" wrote: Something is wrong with the first part of your ElseIf statement, namely this part... Weekday(Date,vbMonday) = 2 < 7 What is "equal 2, less than 7" supposed to mean? What test are you trying to perform? -- Rick (MVP - Excel) "chrisnsmith" wrote in message ... I'm having a problem with the If and Elseif functions. When I enter the following everything works fine. If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells(13, 2).Value = Date - 3 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ElseIf Weekday(Date,vbMonday) = 2 < 7 And Worksheets("Cus Futures") _ .Cells(1, 1).Value = Date -1 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With I only list two worksheets for simplicities sake, however I have 31 worksheets that need to be updated daily. So I have placed all worksheets to update in a module called UpdateForms and did the following. I changed my If statement to; If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells (1, 1). Value = Date -3 Then Call UpdateForms End if When I run this I get a message End If without a block If. I changed both my If statement and Elseif statement to: If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells (1, 1). Value = Date -3 Then Call UpdateForms Elseif Weekday(Date, vbMonday) =2 < 7 And Worksheets("Cus Futures") _ .Cells (1, 1).Value = Date - 1 Then Call UpdateForms When I run this code I get a similar message Else without an If. What am I doing wrong and how do I correct it? |
#7
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Ok, I made the changes to the Elseif statement.
Now, how do I put my procedure(UpdateForms) in a separate module and have it called from the (This Workbook) module? "Rick Rothstein" wrote: You can't do it that way... you can't do a double test in a single logical expression. However, VB's Weekday function calculate starting with any day of the week, so let's start with Tuesday. Give this ElseIf statement a try... ElseIf Weekday(Date, vbTuesday) < 5 And Worksheets("Cus Futures").Cells(1, 1).Value = Date -1 Then -- Rick (MVP - Excel) "chrisnsmith" wrote in message ... If it is Tuesday thru Friday "Rick Rothstein" wrote: Something is wrong with the first part of your ElseIf statement, namely this part... Weekday(Date,vbMonday) = 2 < 7 What is "equal 2, less than 7" supposed to mean? What test are you trying to perform? -- Rick (MVP - Excel) "chrisnsmith" wrote in message ... I'm having a problem with the If and Elseif functions. When I enter the following everything works fine. If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells(13, 2).Value = Date - 3 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ElseIf Weekday(Date,vbMonday) = 2 < 7 And Worksheets("Cus Futures") _ .Cells(1, 1).Value = Date -1 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With I only list two worksheets for simplicities sake, however I have 31 worksheets that need to be updated daily. So I have placed all worksheets to update in a module called UpdateForms and did the following. I changed my If statement to; If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells (1, 1). Value = Date -3 Then Call UpdateForms End if When I run this I get a message End If without a block If. I changed both my If statement and Elseif statement to: If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells (1, 1). Value = Date -3 Then Call UpdateForms Elseif Weekday(Date, vbMonday) =2 < 7 And Worksheets("Cus Futures") _ .Cells (1, 1).Value = Date - 1 Then Call UpdateForms When I run this code I get a similar message Else without an If. What am I doing wrong and how do I correct it? |
#8
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
I'm guessing UpdateForms is a subroutine (you didn't show us your complete
code), although I am not sure how self-contained it is (does it have an argument list?) or what its dependencies are (for example, do you have your ranges qualified or not?). Will other subroutines, functions and/or event procedures from other Modules (worksheet code windows included) call it or will it be called only from one worksheet code window? If only one... then just put UpdateForms in that code window too. If more than one... click Insert/Module and put it in that code window (but now you will have to qualify your ranges with worksheet references, probably ActiveWindow, but that is only a guess without seeing your code). Where you put code, and how you structure it, depends on how it is to be used... you haven't really given us enough to know what your intentions are. As for calling it from any other procedure... just use its name (and pass any arguments it may have into it). You might want to look up the Sub Statement and the Function Statement in VB's help files to get a better handle on calling subroutines and functions. -- Rick (MVP - Excel) "chrisnsmith" wrote in message ... Ok, I made the changes to the Elseif statement. Now, how do I put my procedure(UpdateForms) in a separate module and have it called from the (This Workbook) module? "Rick Rothstein" wrote: You can't do it that way... you can't do a double test in a single logical expression. However, VB's Weekday function calculate starting with any day of the week, so let's start with Tuesday. Give this ElseIf statement a try... ElseIf Weekday(Date, vbTuesday) < 5 And Worksheets("Cus Futures").Cells(1, 1).Value = Date -1 Then -- Rick (MVP - Excel) "chrisnsmith" wrote in message ... If it is Tuesday thru Friday "Rick Rothstein" wrote: Something is wrong with the first part of your ElseIf statement, namely this part... Weekday(Date,vbMonday) = 2 < 7 What is "equal 2, less than 7" supposed to mean? What test are you trying to perform? -- Rick (MVP - Excel) "chrisnsmith" wrote in message ... I'm having a problem with the If and Elseif functions. When I enter the following everything works fine. If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells(13, 2).Value = Date - 3 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ElseIf Weekday(Date,vbMonday) = 2 < 7 And Worksheets("Cus Futures") _ .Cells(1, 1).Value = Date -1 Then With Sheets("Cus Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With ' ' With Sheets("House Futures") .Range(" H9:I50").Copy Range("D9:E50") .Range("F9:I50").ClearContents .Range("M2") = Date End With I only list two worksheets for simplicities sake, however I have 31 worksheets that need to be updated daily. So I have placed all worksheets to update in a module called UpdateForms and did the following. I changed my If statement to; If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells (1, 1). Value = Date -3 Then Call UpdateForms End if When I run this I get a message End If without a block If. I changed both my If statement and Elseif statement to: If Weekday(Date, vbMonday) = 1 And Worksheets("Cus Futures") _ .Cells (1, 1). Value = Date -3 Then Call UpdateForms Elseif Weekday(Date, vbMonday) =2 < 7 And Worksheets("Cus Futures") _ .Cells (1, 1).Value = Date - 1 Then Call UpdateForms When I run this code I get a similar message Else without an If. What am I doing wrong and how do I correct it? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Elseif? | Excel Worksheet Functions | |||
Compile Error ElseIf Without If.........But there is an If ! ??? | Excel Discussion (Misc queries) | |||
if elseif | Excel Discussion (Misc queries) | |||
elseif formula | Excel Discussion (Misc queries) | |||
SP3 problems | Excel Discussion (Misc queries) |