View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Posting---If function problem again

I would use Call and I'd qualify all those unqualified ranges:

Private Sub Workbook_Open()
If Weekday(Date, vbMonday) = 2 _
And worksheets("Somesheetnamehere").Cells(1, 1).value = Date - 3 Then
Call My_Procedure
ElseIf Weekday(Date, vbMonday) = 2 _
And worksheets("Somesheetnamehere").Cells(1, 1).value = Date - 1 Then
Call My_Procedure
End If
End Sub


My_Procedu
With Sheets("Cus Futures")
.Range("H9:I50").Copy _
destination:=worksheets("Someotherenamehere").Rang e("D9")
.Range("F9:I50").ClearContents
worksheets("Someotherenamehere").Range("M2").value = Date
End With

'
'
With Sheets("House Futures")
.Range(" H9:I50").Copy _
destination:=worksheets("Someotherenamehere").Rang e("D9:E50")
.Range("F9:I50").ClearContents
worksheets("Someotherenamehere").Range("M2").value = Date
End With

======
Change all those sheet names to what they need to be.

chrisnsmith wrote:

Can someone explain to me why my Excel 2003 is not recognizing ( If )?
I've tried several codes with the If function and my code won't run.

The responses I received from my previous post asked that I post my code.

This is the If...EndIf code.

Private Sub Workbook_Open()
If Weekday(Date, vbMonday) = 2 And Cells(13, 2) = Date - 3 Then GoTo
My_Procedure
End If
End Sub

My_Procedu
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

This is the If...ElseIf code.

Private Sub Workbook_Open()
If Weekday(Date, vbMonday) = 2 And Cells(1, 1) = Date - 3 Then GoTo
My_Procedure
ElseIf Weekday(Date, vbMonday) = 2 And Cells(1, 1) = Date - 1 Then GoTo
My_Procedure
End If
End Sub

My_Procedu
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


--

Dave Peterson