Got to 0 - I do not understand - suggestions

  • Thread starter Thread starter inarobis
  • Start date Start date
I

inarobis

Hello,

Someone can help me on this error to 0

So I have a little sub that copy several times the same sheet (Sheet 2
--> Template) according to the number of name in the rngRange (range)
in sheet1

For example, if I have three names in range rngRange (Report1,
Report2, and Report3) then it will copy three times the sheet2 and I
will rename it accordingly report1, report2 and report3

I am getting Err 0 problem, I could resolve on putting On Error GoTo 0
in the end of the sub. Someone can help me on understanding this
issue :) ?

Ina

'---------------------------------------------------------------------------------------------
Public Sub CreateReportRange()
On Error GoTo CreateReportRange_Err

Dim strSheetName As String
Dim rngCell As Range

If ActiveWorkbook Is Nothing Then Exit Sub

Sheets("Sheet1").Select

For Each rngCell In Range("rngRange").Cells
strSheetName = rngCell
Sheets("Sheet2").Copy After:=Sheets("Sheet2")
ActiveSheet.name = strSheetName
Next rngCell


CreateReportRange_Err:
MsgBox "CreateReportRange_Err " & Err.Description & " " & Err.Number
End Sub

'---------------------------------------------------------------------------------------------------------------
 
Ina,
You forget the "Exit Sub" ahead of the error handler...
'--
Next rngCell
Exit Sub
CreateReportRange_Err:
'--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



<[email protected]>
wrote in message
Hello,
Someone can help me on this error to 0
So I have a little sub that copy several times the same sheet (Sheet 2
--> Template) according to the number of name in the rngRange (range)
in sheet1
For example, if I have three names in range rngRange (Report1,
Report2, and Report3) then it will copy three times the sheet2 and I
will rename it accordingly report1, report2 and report3

I am getting Err 0 problem, I could resolve on putting On Error GoTo 0
in the end of the sub. Someone can help me on understanding this
issue :) ?
Ina
'---
Public Sub CreateReportRange()
On Error GoTo CreateReportRange_Err

Dim strSheetName As String
Dim rngCell As Range

If ActiveWorkbook Is Nothing Then Exit Sub

Sheets("Sheet1").Select

For Each rngCell In Range("rngRange").Cells
strSheetName = rngCell
Sheets("Sheet2").Copy After:=Sheets("Sheet2")
ActiveSheet.name = strSheetName
Next rngCell

CreateReportRange_Err:
MsgBox "CreateReportRange_Err " & Err.Description & " " & Err.Number
End Sub
 
When the For statement finishes it drops into the error handler. You have to
Exit Sub when the For statement is done

Tyro
 
When the For statement finishes it drops into the error handler. You have to
Exit Sub when the For statement is done

Tyro














- Show quoted text -

thanks guys :D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top