+ Reply to Thread
Results 1 to 3 of 3

Stop VBA errors - On error do nothing

Hybrid View

  1. #1
    Registered User
    Join Date
    10-15-2011
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    49

    Cool Stop VBA errors - On error do nothing

    Hello,

    I need some basic advice on what to do when my VBA code runs into errors..

    I have this bit of code to delete sheets tabs

    Formula: copy to clipboard
    Dim MyCell As Range, MyRange As Range

    Set MyRange = Sheets("AREAS").Range("A2")
    Set MyRange = Range(MyRange, MyRange.End(xlDown))

    For Each MyCell In MyRange


    Application.DisplayAlerts = False
    Sheets(MyCell.Value).Delete
    Application.DisplayAlerts = True


    Next MyCell


    When the sheet tabs are not there to delete I want it to not come up with an error.

    I thought the code would be something like on error do nothing

    Can someone help with what to put that I could use in other code too to just make the code not error and whether to put the code where the error occurs or at the end?

    Thanks in advance to anybody who can assist
    Last edited by ExcelGal; 07-17-2012 at 08:53 AM.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Stop VBA errors - On error do nothing

    something like:
    Sub test()
    On Error GoTo handler
    
    'Your code here.....
    
    Exit Sub
    
    
    handler:
        MsgBox "Oops, something went wrong!" & vbCr & "Error Msg: " & Err.Description, vbCritical + vbDefaultButton1
    End Sub

  3. #3
    Registered User
    Join Date
    10-15-2011
    Location
    Manchester
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Stop VBA errors - On error do nothing

    thanks again! worked

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1