Check If Named Range Exists Before Delete

  • Hi All,


    I'm trying to check if a named range "ActiveCells" exists before deleting it in VBA but can't seem to get the syntax right, I have tried:

    Code
    If Range("Activecells") Is Nothing Then Resume Next Else: ActiveWorkbook.Names("ActiveCells").Delete
    
    
    'AND
    
    
        If ActiveWorkbook.Names("Activecells") Is Nothing Then Resume Next Else: ActiveWorkbook.Names("ActiveCells").Delete


    Can anyone point me in the right direction? I have tried searching but I can only find threads about checking for named objects or about using the toolbars to add/delete named ranges.


    Thanks!
    Averil[hr]*[/hr] Auto Merged Post;[dl]*[/dl]Sorry - I did find this one in the answers above after my post was submitted but not in my original search:


    http://www.ozgrid.com/forum/showthread.php?t=76641


    Thanks,
    Averil

    -------------
    [FONT="Comic Sans MS"]Averil Pretty[/FONT]

  • Re: Check If Named Range Exists Before Delete


    I wouldn't bother checking and just delete it with use of On Error Resume Next to stop any run time errors.


    Checking things with If Statements can slow code down and is sometimes superfluous.


    Thanks for posting back with solution though.

  • Re: Check If Named Range Exists Before Delete


    Thanks Dave,


    I did have the On Error Resume Next in there but am debugging (like you told me :smile:) so wanted to stop getting the error I was getting and being curious I wanted to see what the workaround was.


    Cheers,
    AP

    -------------
    [FONT="Comic Sans MS"]Averil Pretty[/FONT]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!