Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Problem with multiple error handling

I wrote a macro to copy data from multiple worksheets on a spreadsheet that I
receive each day. If there is no data to report for one of the worksheets the
worksheet is not included in the spreadsheet that I receive. Therefore I used
multiple On Error statements in my macro (one for each worksheet that may be
missing) to jump to an error handling section for each worksheet to handle
the missing sheet, then jump back into my macro at the section that deals
with the data on the next sheet. The problem that I have is that if more than
one worksheet is missing from the spreadsheet that I receive, then my macro
stops with an error on the second missing worksheet. I have tried inserting
On Error GoTo 0 statements to reset my error handling but that does not help.
What am I doing wrong?
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Problem with multiple error handling

Sorry, below is my macro:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 10/15/2007 by Douglas L. Eakle
'

'
ChDir _
"\\Shafsv01\data\COMMON\DAILY PERFORMANCE REVIEW MEETING\HOURLY LMP
PRICING"
Workbooks.Open Filename:= _
"\\Shafsv01\data\COMMON\DAILY PERFORMANCE REVIEW MEETING\HOURLY LMP
PRICING\Day Ahead Obligation.xls"
On Error GoTo ErrorHandler1 'Enable error handling for Unit 1 data
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
Unit2:

Windows("Day Ahead Obligation.xls").Activate
On Error GoTo ErrorHandler2 'Enable error handling for Unit 2 data
Sheets("Harrison 2").Select
Range("A3:C3").Select
Application.CutCopyMode = False
Selection.Copy
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("G4").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("H7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Unit3:

Windows("Day Ahead Obligation.xls").Activate
On Error GoTo ErrorHandler3 'Enable error handling for Unit 3 data
Sheets("Harrison 3").Select
Range("A3:C3").Select
Application.CutCopyMode = False
Selection.Copy
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("L4").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("M7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Lastline:
Windows("Day Ahead Obligation.xls").Activate
ActiveWorkbook.Close SaveChanges:=False
Range("A1").Select
Application.CutCopyMode = False
ActiveWorkbook.Save
Exit Sub 'Exit to avoid error handling
ErrorHandler1: 'Error handling routine for Unit 1 data
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("C7:D30").Select
Selection.ClearContents
GoTo Unit2
'
ErrorHandler2: 'Error handling routine for Unit 2 data
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("H7:I30").Select
Selection.ClearContents
GoTo Unit3
'
ErrorHandler3: 'Error handling routine for Unit 3 data
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("M7:N30").Activate
Selection.ClearContents
GoTo Lastline


End Sub

"Don Guillett" wrote:

Always nice to post your efforts for comments

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"DOOGIE" wrote in message
...
I wrote a macro to copy data from multiple worksheets on a spreadsheet that
I
receive each day. If there is no data to report for one of the worksheets
the
worksheet is not included in the spreadsheet that I receive. Therefore I
used
multiple On Error statements in my macro (one for each worksheet that may
be
missing) to jump to an error handling section for each worksheet to handle
the missing sheet, then jump back into my macro at the section that deals
with the data on the next sheet. The problem that I have is that if more
than
one worksheet is missing from the spreadsheet that I receive, then my
macro
stops with an error on the second missing worksheet. I have tried
inserting
On Error GoTo 0 statements to reset my error handling but that does not
help.
What am I doing wrong?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Problem with multiple error handling

Hi Doogie, You could probably solve the problem by using an If...Then...Else
statement instead of the error handler. ex:

If Not Sheets("Harrison1") is Nothing Then
'Do the copy and paste
Else
'Do the range delete.
End If

That would eliminate extra code for the error handlers also.

"DOOGIE" wrote:

Sorry, below is my macro:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 10/15/2007 by Douglas L. Eakle
'

'
ChDir _
"\\Shafsv01\data\COMMON\DAILY PERFORMANCE REVIEW MEETING\HOURLY LMP
PRICING"
Workbooks.Open Filename:= _
"\\Shafsv01\data\COMMON\DAILY PERFORMANCE REVIEW MEETING\HOURLY LMP
PRICING\Day Ahead Obligation.xls"
On Error GoTo ErrorHandler1 'Enable error handling for Unit 1 data
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
Unit2:

Windows("Day Ahead Obligation.xls").Activate
On Error GoTo ErrorHandler2 'Enable error handling for Unit 2 data
Sheets("Harrison 2").Select
Range("A3:C3").Select
Application.CutCopyMode = False
Selection.Copy
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("G4").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("H7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Unit3:

Windows("Day Ahead Obligation.xls").Activate
On Error GoTo ErrorHandler3 'Enable error handling for Unit 3 data
Sheets("Harrison 3").Select
Range("A3:C3").Select
Application.CutCopyMode = False
Selection.Copy
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("L4").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("M7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Lastline:
Windows("Day Ahead Obligation.xls").Activate
ActiveWorkbook.Close SaveChanges:=False
Range("A1").Select
Application.CutCopyMode = False
ActiveWorkbook.Save
Exit Sub 'Exit to avoid error handling
ErrorHandler1: 'Error handling routine for Unit 1 data
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("C7:D30").Select
Selection.ClearContents
GoTo Unit2
'
ErrorHandler2: 'Error handling routine for Unit 2 data
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("H7:I30").Select
Selection.ClearContents
GoTo Unit3
'
ErrorHandler3: 'Error handling routine for Unit 3 data
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("M7:N30").Activate
Selection.ClearContents
GoTo Lastline


End Sub

"Don Guillett" wrote:

Always nice to post your efforts for comments

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"DOOGIE" wrote in message
...
I wrote a macro to copy data from multiple worksheets on a spreadsheet that
I
receive each day. If there is no data to report for one of the worksheets
the
worksheet is not included in the spreadsheet that I receive. Therefore I
used
multiple On Error statements in my macro (one for each worksheet that may
be
missing) to jump to an error handling section for each worksheet to handle
the missing sheet, then jump back into my macro at the section that deals
with the data on the next sheet. The problem that I have is that if more
than
one worksheet is missing from the spreadsheet that I receive, then my
macro
stops with an error on the second missing worksheet. I have tried
inserting
On Error GoTo 0 statements to reset my error handling but that does not
help.
What am I doing wrong?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Problem with multiple error handling

I added an If...Then...Else statement
If Not Sheets ("Harrison 1") is Nothing Then
'Do the copy and paste
Else
'Do the range delete
End If

However, when my macro gets to the statement "If Not Sheets ("Harrison 1")
is Nothing Then" and there is no sheet "Harrison 1", it returns a runtime
error "9" "subscript out of range" error and stops. What am I doing wrong?

"JLGWhiz" wrote:

Hi Doogie, You could probably solve the problem by using an If...Then...Else
statement instead of the error handler. ex:

If Not Sheets("Harrison1") is Nothing Then
'Do the copy and paste
Else
'Do the range delete.
End If

That would eliminate extra code for the error handlers also.

"DOOGIE" wrote:

Sorry, below is my macro:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 10/15/2007 by Douglas L. Eakle
'

'
ChDir _
"\\Shafsv01\data\COMMON\DAILY PERFORMANCE REVIEW MEETING\HOURLY LMP
PRICING"
Workbooks.Open Filename:= _
"\\Shafsv01\data\COMMON\DAILY PERFORMANCE REVIEW MEETING\HOURLY LMP
PRICING\Day Ahead Obligation.xls"
On Error GoTo ErrorHandler1 'Enable error handling for Unit 1 data
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
Unit2:

Windows("Day Ahead Obligation.xls").Activate
On Error GoTo ErrorHandler2 'Enable error handling for Unit 2 data
Sheets("Harrison 2").Select
Range("A3:C3").Select
Application.CutCopyMode = False
Selection.Copy
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("G4").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("H7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Unit3:

Windows("Day Ahead Obligation.xls").Activate
On Error GoTo ErrorHandler3 'Enable error handling for Unit 3 data
Sheets("Harrison 3").Select
Range("A3:C3").Select
Application.CutCopyMode = False
Selection.Copy
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("L4").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("M7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Lastline:
Windows("Day Ahead Obligation.xls").Activate
ActiveWorkbook.Close SaveChanges:=False
Range("A1").Select
Application.CutCopyMode = False
ActiveWorkbook.Save
Exit Sub 'Exit to avoid error handling
ErrorHandler1: 'Error handling routine for Unit 1 data
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("C7:D30").Select
Selection.ClearContents
GoTo Unit2
'
ErrorHandler2: 'Error handling routine for Unit 2 data
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("H7:I30").Select
Selection.ClearContents
GoTo Unit3
'
ErrorHandler3: 'Error handling routine for Unit 3 data
Windows("DAY AHEAD LMP SHEET.xls").Activate
Range("M7:N30").Activate
Selection.ClearContents
GoTo Lastline


End Sub

"Don Guillett" wrote:

Always nice to post your efforts for comments

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"DOOGIE" wrote in message
...
I wrote a macro to copy data from multiple worksheets on a spreadsheet that
I
receive each day. If there is no data to report for one of the worksheets
the
worksheet is not included in the spreadsheet that I receive. Therefore I
used
multiple On Error statements in my macro (one for each worksheet that may
be
missing) to jump to an error handling section for each worksheet to handle
the missing sheet, then jump back into my macro at the section that deals
with the data on the next sheet. The problem that I have is that if more
than
one worksheet is missing from the spreadsheet that I receive, then my
macro
stops with an error on the second missing worksheet. I have tried
inserting
On Error GoTo 0 statements to reset my error handling but that does not
help.
What am I doing wrong?


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
Error handling problem Jim G Excel Discussion (Misc queries) 2 October 3rd 07 02:19 AM
Problem with handling on error when file is already open Frank Excel Programming 3 September 22nd 06 04:26 PM
Error Handling problem Brassman[_5_] Excel Programming 3 May 24th 05 03:43 PM
Error Handling Problem Minitman[_4_] Excel Programming 3 November 15th 04 06:52 AM
Excel VBA - Error handling problem brutalmetal[_2_] Excel Programming 2 January 21st 04 03:17 AM


All times are GMT +1. The time now is 11:45 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"