Still having problems with If --Elseif
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?
|