Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default On error resume next not working

the following code is supposed to print sheet2 if there is a sheet two, then
delete sheet2. So the first part checks if there is content on sheet2("A1")
and prints it. If ther is no content on sheet2 the error handler skips this
step. Then it is supposed to delete sheet2. If there is no sheet2 the error
handler resume next is supposed to skip this part but it is not. If there is
no sheet2 the line-Worksheets("Sheet2").Delete, returns a runtime error 9.

Why does the on error resume next not working? Thanks

Sub print()
On Error GoTo skipprint

If Not Worksheets("Sheet2").Range("A1").Value = "" Then
If MsgBox("You have trades that need to be placed manually. Do you want to
print them?", vbYesNo) = vbYes Then
Worksheets("Sheet2").Rows.AutoFit
Worksheets("Sheet2").Columns.AutoFit
Worksheets("Sheet2").PrintOut

Else
skipprint:
End If
End If

MsgBox ("If prompted select 'Delete' or this will not work.")
On Error Resume Next
Worksheets("Sheet2").Delete

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default On error resume next not working

Try the below...Please note that there is a separate function to check
whether the sheet exists or not...

Sub MacroPrint()
If SheetExist("Sheet2") Then
If Worksheets("Sheet2").Range("A1") = "" Then
If MsgBox("You have trades that need to be placed manually." & _
"Do you want to print them?", vbYesNo) = vbYes Then
Worksheets("Sheet2").Rows.AutoFit
Worksheets("Sheet2").Columns.AutoFit
Worksheets("Sheet2").PrintOut Copies:=1, Collate:=True
End If
End If
Application.DisplayAlerts = False
Sheets("Sheet2").Delete
Application.DisplayAlerts = True
End If
End Sub

Function SheetExist(strSheet As String) As Boolean
On Error Resume Next
SheetExist = Not (Sheets(strSheet) Is Nothing)
End Function

If this post helps click Yes
---------------
Jacob Skaria


"cluckers" wrote:

the following code is supposed to print sheet2 if there is a sheet two, then
delete sheet2. So the first part checks if there is content on sheet2("A1")
and prints it. If ther is no content on sheet2 the error handler skips this
step. Then it is supposed to delete sheet2. If there is no sheet2 the error
handler resume next is supposed to skip this part but it is not. If there is
no sheet2 the line-Worksheets("Sheet2").Delete, returns a runtime error 9.

Why does the on error resume next not working? Thanks

Sub print()
On Error GoTo skipprint

If Not Worksheets("Sheet2").Range("A1").Value = "" Then
If MsgBox("You have trades that need to be placed manually. Do you want to
print them?", vbYesNo) = vbYes Then
Worksheets("Sheet2").Rows.AutoFit
Worksheets("Sheet2").Columns.AutoFit
Worksheets("Sheet2").PrintOut

Else
skipprint:
End If
End If

MsgBox ("If prompted select 'Delete' or this will not work.")
On Error Resume Next
Worksheets("Sheet2").Delete

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default On error resume next not working

This works great. Not exactly sure how the function works though. Currious
as to why my on error resume next was not working. Do you know?

"cluckers" wrote:

the following code is supposed to print sheet2 if there is a sheet two, then
delete sheet2. So the first part checks if there is content on sheet2("A1")
and prints it. If ther is no content on sheet2 the error handler skips this
step. Then it is supposed to delete sheet2. If there is no sheet2 the error
handler resume next is supposed to skip this part but it is not. If there is
no sheet2 the line-Worksheets("Sheet2").Delete, returns a runtime error 9.

Why does the on error resume next not working? Thanks

Sub print()
On Error GoTo skipprint

If Not Worksheets("Sheet2").Range("A1").Value = "" Then
If MsgBox("You have trades that need to be placed manually. Do you want to
print them?", vbYesNo) = vbYes Then
Worksheets("Sheet2").Rows.AutoFit
Worksheets("Sheet2").Columns.AutoFit
Worksheets("Sheet2").PrintOut

Else
skipprint:
End If
End If

MsgBox ("If prompted select 'Delete' or this will not work.")
On Error Resume Next
Worksheets("Sheet2").Delete

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default On error resume next not working

Read Chip Pearson's site on error handling:
http://www.cpearson.com/Excel/ErrorHandling.htm

You'll want to read this portion "Enabled And Active Error Handlers"
specifically.

cluckers wrote:

This works great. Not exactly sure how the function works though. Currious
as to why my on error resume next was not working. Do you know?

"cluckers" wrote:

the following code is supposed to print sheet2 if there is a sheet two, then
delete sheet2. So the first part checks if there is content on sheet2("A1")
and prints it. If ther is no content on sheet2 the error handler skips this
step. Then it is supposed to delete sheet2. If there is no sheet2 the error
handler resume next is supposed to skip this part but it is not. If there is
no sheet2 the line-Worksheets("Sheet2").Delete, returns a runtime error 9.

Why does the on error resume next not working? Thanks

Sub print()
On Error GoTo skipprint

If Not Worksheets("Sheet2").Range("A1").Value = "" Then
If MsgBox("You have trades that need to be placed manually. Do you want to
print them?", vbYesNo) = vbYes Then
Worksheets("Sheet2").Rows.AutoFit
Worksheets("Sheet2").Columns.AutoFit
Worksheets("Sheet2").PrintOut

Else
skipprint:
End If
End If

MsgBox ("If prompted select 'Delete' or this will not work.")
On Error Resume Next
Worksheets("Sheet2").Delete

End Sub


--

Dave Peterson
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
Autofill & On Error Resume Next Dandelo Excel Discussion (Misc queries) 2 August 21st 08 07:14 PM
On Error Resume Next problem Jim May Excel Discussion (Misc queries) 14 November 2nd 07 12:27 PM
On Error Resume Next (when next statement is Do Loop ...) EagleOne Excel Discussion (Misc queries) 2 September 26th 06 03:26 PM
resume.xlw OZDOC Excel Discussion (Misc queries) 6 July 31st 06 01:24 PM
On error resume next problem freekrill Excel Discussion (Misc queries) 2 December 7th 05 12:51 AM


All times are GMT +1. The time now is 11:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"