Results 1 to 10 of 83

Thread: Delete rows based on match criteria in two excel files or single Excel File

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    On Error Resume Next is one of a few ways to do “Error handling in VBA” ( http://www.excelfox.com/forum/showth...GoRoT-N0Nula-1 )

    On Error Resume Next at the start of your program will tell VBA to keep going even if it crashes or has problems many times.
    It is like you go on a long journey in your car. But you decide to drive very fast and if you have lots of crashes and accidents you just keep going very fast and ignore all your accidents and crashes.
    This can do damage and break things.

    It does not just stop the error message. It does stop the error message , you are correct , … but also it does keep going even if things are broken or not working properly. This might do bad damage. You may not notice this damage until something else goes badly wrong. It may cause lots of confusing problems later.

    On Error Resume Next at the start of your program is dangerous. You may be lucky one day and it will cause no problems. Or you may be unlucky and it will cause lots of problems and cause lots of damage.


    Usually there is a better way to achieve what you want without Error Handling.


    Some ways to use Error handling are not too bad.
    For example:

    This is very Bad
    Code:
    Sub BadErrorHandling()
    On Error Resume Next ' Error handling is ON
    Dim Nmbr As Long: Let Nmbr = 0
    
    '
    '  code
    ''  code
    ''  code
    ''  code
    ''  code
    ''  code
    ''  code
    ''  code
    ''  code
    '
    
     Let Nmbr = 1 / Nmbr
    
     '
     '
     '  code
    ''  code
    ''  code
    ''  code
    ''  code
    ''  code
    '
    End Sub
    This is not so bad

    Code:
    Sub NotSoBadErrorHandling()
    
    Dim Nmbr As Long: Let Nmbr = 0
    
    '
    '  code
    ''  code
    ''  code
    ''  code
    ''  code
    ''  code
    ''  code
    ''  code
    ''  code
    '
    On Error Resume Next ' Error handling is ON
     Let Nmbr = 1 / Nmbr
    On Error GoTo 0      ' Error handling is OFF
     '
     '
     '  code
    ''  code
    ''  code
    ''  code
    ''  code
    ''  code
    '
    End Sub
    The last macro is not so bad because you only use the error handling for a short piece of the code which you think may error.

    But it is still better to do it without error handling

    Code:
    Sub AlternativeToErrorHandling()
    
    Dim Nmbr As Long: Let Nmbr = 0
    
    '
    '  code
    ''  code
    ''  code
    ''  code
    ''  code
    ''  code
    ''  code
    ''  code
    ''  code
    '
    
        If Nmbr <> 0 Then Let Nmbr = 1 / Nmbr
    
     '
     '
     '  code
    ''  code
    ''  code
    ''  code
    ''  code
    ''  code
    '
    End Sub

    Alan
    Last edited by DocAElstein; 03-23-2020 at 10:09 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    KILL A MODERATOR!!

Similar Threads

  1. Replies: 29
    Last Post: 06-09-2020, 06:00 PM
  2. Replies: 3
    Last Post: 10-20-2015, 12:51 PM
  3. VBA To Delete Rows Based On Value Criteria In A Column
    By jffryjsphbyn in forum Excel Help
    Replies: 1
    Last Post: 08-15-2013, 12:45 PM
  4. Replies: 6
    Last Post: 08-14-2013, 04:25 PM
  5. Delete Remove Rows By Criteria VBA Excel
    By marreco in forum Excel Help
    Replies: 5
    Last Post: 12-20-2012, 05:56 PM

Tags for this Thread

Posting Permissions

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