Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default On Error Issues


I'm having issues capturing an error and using it to direct the code.
Here is the code I'm trying to execute:

Public Sub sheetCheck()
cNodes = ThisWorkbook.Names("Nodes").RefersToRange.Rows.Cou nt
For i = 1 To cNodes
On Error GoTo NewSheet
isThere = True
sheetName = sheetBase & i
Sheets(sheetName).Visible = False
check: If Not isThere Then Sheets("Scoring Sheet 0 (2)").Name =
sheetName
Next i
Exit Sub
NewSheet: Scoring_0.Copy after:=Scoring_0
isThere = False
GoTo check
End Sub

Nodes refers to a list of nodes for this system. The sheets are named
Scoring x, where x would be replaced by i in the loop. The code will
execute perfectly through one error, but if I have more than one
non-existent sheet, it fails.

Cheers-
Chris


--
cmk18
------------------------------------------------------------------------
cmk18's Profile: http://www.excelforum.com/member.php...fo&userid=6047
View this thread: http://www.excelforum.com/showthread...hreadid=386540

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default On Error Issues

I think you need to reset the error check

On Error goto 0

place this after
NewSheet:

--
steveB

Remove "AYN" from email to respond
"cmk18" wrote in
message ...

I'm having issues capturing an error and using it to direct the code.
Here is the code I'm trying to execute:

Public Sub sheetCheck()
cNodes = ThisWorkbook.Names("Nodes").RefersToRange.Rows.Cou nt
For i = 1 To cNodes
On Error GoTo NewSheet
isThere = True
sheetName = sheetBase & i
Sheets(sheetName).Visible = False
check: If Not isThere Then Sheets("Scoring Sheet 0 (2)").Name =
sheetName
Next i
Exit Sub
NewSheet: Scoring_0.Copy after:=Scoring_0
isThere = False
GoTo check
End Sub

Nodes refers to a list of nodes for this system. The sheets are named
Scoring x, where x would be replaced by i in the loop. The code will
execute perfectly through one error, but if I have more than one
non-existent sheet, it fails.

Cheers-
Chris


--
cmk18
------------------------------------------------------------------------
cmk18's Profile:
http://www.excelforum.com/member.php...fo&userid=6047
View this thread: http://www.excelforum.com/showthread...hreadid=386540



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default On Error Issues

Once an error is raised, VBA is operating in "error mode". You
need to cause it to resume in "normal mode" by using a Resume
statement. Change your

GoTo check
' to
Resume check


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"cmk18"
wrote in message
...

I'm having issues capturing an error and using it to direct the
code.
Here is the code I'm trying to execute:

Public Sub sheetCheck()
cNodes = ThisWorkbook.Names("Nodes").RefersToRange.Rows.Cou nt
For i = 1 To cNodes
On Error GoTo NewSheet
isThere = True
sheetName = sheetBase & i
Sheets(sheetName).Visible = False
check: If Not isThere Then Sheets("Scoring Sheet 0 (2)").Name
=
sheetName
Next i
Exit Sub
NewSheet: Scoring_0.Copy after:=Scoring_0
isThere = False
GoTo check
End Sub

Nodes refers to a list of nodes for this system. The sheets
are named
Scoring x, where x would be replaced by i in the loop. The
code will
execute perfectly through one error, but if I have more than
one
non-existent sheet, it fails.

Cheers-
Chris


--
cmk18
------------------------------------------------------------------------
cmk18's Profile:
http://www.excelforum.com/member.php...fo&userid=6047
View this thread:
http://www.excelforum.com/showthread...hreadid=386540



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default On Error Issues

You could use a separate function that checks for existence of the worksheet.

It might make it easier to read your code when you come back to it, too.

Function WorksheetExists(SheetName As Variant, _
Optional WhichBook As Workbook) As Boolean
'from Chip Pearson
Dim WB As Workbook
Set WB = IIf(WhichBook Is Nothing, ThisWorkbook, WhichBook)
On Error Resume Next
WorksheetExists = CBool(Len(WB.Worksheets(SheetName).Name) 0)
End Function

Public Sub sheetCheck()
cNodes = ThisWorkbook.Names("Nodes").RefersToRange.Rows.Cou nt
For i = 1 To cNodes
sheetName = sheetBase & i
if worksheetsexists(sheetname, thisworkbook) then
'it exists
else
'it doesn't exist
end if
next i

End Sub

cmk18 wrote:

I'm having issues capturing an error and using it to direct the code.
Here is the code I'm trying to execute:

Public Sub sheetCheck()
cNodes = ThisWorkbook.Names("Nodes").RefersToRange.Rows.Cou nt
For i = 1 To cNodes
On Error GoTo NewSheet
isThere = True
sheetName = sheetBase & i
Sheets(sheetName).Visible = False
check: If Not isThere Then Sheets("Scoring Sheet 0 (2)").Name =
sheetName
Next i
Exit Sub
NewSheet: Scoring_0.Copy after:=Scoring_0
isThere = False
GoTo check
End Sub

Nodes refers to a list of nodes for this system. The sheets are named
Scoring x, where x would be replaced by i in the loop. The code will
execute perfectly through one error, but if I have more than one
non-existent sheet, it fails.

Cheers-
Chris

--
cmk18
------------------------------------------------------------------------
cmk18's Profile: http://www.excelforum.com/member.php...fo&userid=6047
View this thread: http://www.excelforum.com/showthread...hreadid=386540


--

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
Linking issues lost then found Excel Discussion (Misc queries) 3 January 12th 09 10:50 AM
rounding issues [email protected] New Users to Excel 1 February 27th 06 09:16 PM
After SP2, excel having issues Gopi Excel Discussion (Misc queries) 2 February 12th 06 12:29 PM
need help for several issues bandy2000 Excel Programming 2 March 15th 05 02:11 AM
More date issues Erik[_6_] Excel Programming 3 March 1st 04 07:59 PM


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