Error 9

backup69

Active Member
Joined
Jan 20, 2004
Messages
271
Hi all

Why my code stop on the second error "Subscript out of range"?
Code:
Dim LC As Integer, FB As Integer
Dim Ws As Worksheet
Application.ScreenUpdating = False
For Each Ws In ActiveWorkbook.Worksheets
On Error GoTo nextsh
LC = Ws.Range([A1], Ws.UsedRange).Columns.Count
ActiveWindow.View = xlPageBreakPreview

FB = Ws.VPageBreaks(1).Location.Column

'here i have other commands

nextsh:
Next Ws
FB = Ws.VPageBreaks(1).Location.Column
If first sheet give me error here, code jump to the errorhandler(nextsh). But if this part of code give error second time i got orror on the screen and code stop.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
no

If my code check the first sheet and got error because sheet dont have pagebreakes and this is ok. Other code ignored and i want check next sheet. But now in the same place where i check pagebreake my code stop and not ignore error like i want "On Error GoTo nextsh".
 
Upvote 0
Why not check for page breaks instead of relying on error handling?
Code:
If Ws.VPageBreaks.Count<>0 Then
   ' do stuff
Else
   Msgbox Ws.Name & " has no vertical page breaks."
End If
 
Upvote 0
Yes Norie you right
And ty erik to for your link
in my case simple Err.Clear not working but solution is:
Code:
On Error Resume Next
FB = Ws.VPageBreaks(1).Location.Column 
if err.number = 9 then goto nextsh

nextsh: 
Err.Clear 
Next Ws

Ty all
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,891
Members
449,058
Latest member
Guy Boot

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top