VBA Error Handling to turn Functionality Back On

oblix

Board Regular
Joined
Mar 29, 2017
Messages
183
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
  6. 2011
  7. 2010
  8. 2007
  9. 2003 or older
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
Hi there

In my macro/Subs I start with Call Turn Functionality off (sub) and at the end Call Turn Functionality On (sub)
This are macros to turn certain things on and off to speed up calculations and stop screen flickering
If the macro is interupted or error occures, can I add error handling to at least turn functionality back on
I Have provided a sample of one of the subs if someone could assist to show how to add error handling:

VBA Code:
Sub FILTER_PERMEXPORT()

   TurnOffFunctionality
    
    ThisWorkbook.Worksheets("Perm Transfer").Range("O3:Z1000").ClearContents
    
    Sheets("PERMENANT LIVING IN REGISTER").Range("C4:AV500").AdvancedFilter Action _
                      :=xlFilterCopy, CriteriaRange:=Range("'Perm Transfer'!Criteria_P"), _
                      CopyToRange:=Range("'Perm Transfer'!Extract_P"), Unique:=False
    
    Call Sort_perm2
   
        
    TurnOnFunctionality
    
End Sub

I will then attemp to do the rest with other macros
Thank you
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi,
try
Rich (BB code):
Sub FILTER_PERMEXPORT()

   On Error GoTo myerror
   TurnOffFunctionality
   
    ThisWorkbook.Worksheets("Perm Transfer").Range("O3:Z1000").ClearContents
    
    Sheets("PERMENANT LIVING IN REGISTER").Range("C4:AV500").AdvancedFilter Action _
                      :=xlFilterCopy, CriteriaRange:=Range("'Perm Transfer'!Criteria_P"), _
                      CopyToRange:=Range("'Perm Transfer'!Extract_P"), Unique:=False
    
    Call Sort_perm2
  
       
myerror:
    TurnOnFunctionality
    'report error
    If Err <> 0 Then MsgBox (Error(Err)), 48, "Error"
   
End Sub

Dave
 
Upvote 0
Solution
Thank you dmt32
Just to be sure...... if the code runs complete it will stil turn on functionality although it is in myerror?
 
Upvote 0
Thank you Dave
Just to be sure...... if the code runs complete it will stil turn on functionality although it is in myerror?

If your code errors then it goes straight to the myerror label where your function is called & then msgbox display the error message.
If no error, your function will still be called but msgbox will not display.

Dave
 
Upvote 0
Wow thank you
 
Upvote 0

Forum statistics

Threads
1,214,626
Messages
6,120,602
Members
448,974
Latest member
ChristineC

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