Error handling only works in step thru

S Oberlander

Board Regular
Joined
Nov 25, 2020
Messages
147
Office Version
  1. 365
Platform
  1. Windows
The below code depends on another macro to have run first, so I put in some code to check if that macro ran and if not to call it.
It is also designed to be able to get called multiple times, and to skip some steps if it is being run the second time.

My code works when I step thru it. It also works if the first macro NonqualRates ran already, but if NonqualRates did not run yet it gets stuck by If Sheets("Exceptions").Visible = False Then; giving me Run-time error '9": subscript out of range.
What am I doing wrong? I told the code what it is supposed to do in case of an error.

Note, the way I check if the given macro ran already is by checking for a sheet that gets added and named within that macro

VBA Code:
Sub IqmPossibile()

    On Error GoTo firstep
    If Sheets("Pivot").Visible = True Then GoTo secondstep
firstep: 'runs NonqualRatesl 
    Call NonqualRates
secondstep: 'checks if this is first run for IqmPossible
    On Error GoTo thirdstep
    If Sheets("Exceptions").Visible = False Then GoTo fourthstep 'this is where it gets stuck; the "False" here is not a mistake, it is checking for a hidden sheet.
thirdstep: 'does this only if it is the first run
    On Error GoTo 0
     'long winded stuff happen here, not relevant to my question
fourthstep: 'continue to userform
    IQMPossibilities.show vbModeless
    
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
You cannot use error handling like, have a look here as to why On Error WTF?

Which sheet gets added by the NonqualRates code?
 
Upvote 0
Ok you can test for that like
VBA Code:
   If Not Evaluate("isref(Pivot!A1)") Then
      Call NonqualRates
   End If
 
Upvote 0
Solution
Ok you can test for that like
VBA Code:
   If Not Evaluate("isref(Pivot!A1)") Then
      Call NonqualRates
   End If
So for the Exceptions sheet I can do
VBA Code:
   If Evaluate("isref(Exceptions!A1)") Then
      'here I want it should skip straight to the userform
   End If
which is much neater and probably the smarter way to do it too
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,684
Members
449,048
Latest member
81jamesacct

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