Thread
:
Problem with If-Then-Else Statement
View Single Post
#
4
Posted to microsoft.public.excel.programming
Don Guillett
external usenet poster
Posts: 10,124
Problem with If-Then-Else Statement
try it like this
Sub copyifn()
Set mywb = Workbooks("DAY AHEAD LMP SHEET.xls")
On Error GoTo next1
Sheets("joe").Range("a1").Copy
mywb.Sheets("try this").Range("h1").PasteSpecial Paste:=xlPasteValues
next1:
On Error GoTo next2
Sheets("Sheet4").Range("f2:h4").Copy
mywb.Sheets("try this").Range("h3").PasteSpecial Paste:=xlPasteValues
next2:
MsgBox "done"
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"DOOGIE" wrote in message
...
What is wrong with this code:
If Not Sheets("Harrison 1") Is Nothing Then
Sheets("Harrison 1").Select
Range("A3:C3").Select
Selection.Copy
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("B4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Windows("Day Ahead Obligation.xls").Activate
Range("B6:C29").Select
Application.CutCopyMode = False
Selection.Copy
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("C7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Else
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("C7:D30").Select
Selection.ClearContents
End If
If I run this on a spreadsheet where there is no "Harrison 1" sheet, I
receive a runtime error 9 "subscript out of range" on the "If Not
Sheets("Harrison 1") Is Nothing Then" statement.
Reply With Quote
Don Guillett
View Public Profile
Find all posts by Don Guillett