[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

suppressing Excel invalid reference error message

Posted on 2012-12-27
5
Medium Priority
?
660 Views
Last Modified: 2013-01-17
hey guys,

previously mbizup helped me out with deriving this code. but after i run it and it successfully deletes all the named ranges, it still pops up with the invalid reference error message. i'm really not sure how to suppress this error message. could yall help me? thanks!!

On Error Resume Next
Application.DisplayAlerts = False

Dim nr As Name
    
    For Each nr In ActiveWorkbook.Names
        Debug.Print nr.Name
        nr.Delete
    Next
Exit Sub

Open in new window

invalid-reference-pop-up-error-m.png
0
Comment
Question by:developingprogrammer
  • 2
  • 2
5 Comments
 
LVL 50
ID: 38726257
Hello,

The code deletes all named ranges in the workbook.

The error message states that a formula uses a reference that does not exist. This reference may well be a range name that has just been deleted. The formula can be in a cell, in data validation or in a conditional formatting. You'll need to find the formula and then delete THAT.

Can you step back a bit and explain what you are trying to achieve overall? Why do you want to delete all range names?

cheers, teylyn
0
 
LVL 50

Expert Comment

by:Martin Liss
ID: 38727604
At the start of the code put

Application.DisplayAlerts = False

And at the end put

Application.DisplayAlerts = True
0
 

Author Comment

by:developingprogrammer
ID: 38777135
hi there, i have a macro that deletes all the sheets in the excel workbook and then imports those sheets again and then creates the named ranges again. this is done everytime the user runs the report. so when the sheets are deleted, some weird named ranges are created and thus i want to "clean up" before i create the new named ranges again.

the formulas are in the graphs and i need a way to suppress the error messages so it doensn't interupt my code, suppress excel from breaking the code cause of the void in the named ranged references, and then when my later code runs it will relink up the named ranges.

btw application.displayalerts doesn't work but thanks for the help!!
0
 
LVL 50

Accepted Solution

by:
Ingeborg Hawighorst (Microsoft MVP / EE MVE) earned 2000 total points
ID: 38777402
As far as I'm aware, there is no easy way to suppress the message. The topic has recently been discussed among Excel MVPs, with no satisfactory outcome.

One approach that seems to work is to clear the ranges instead of deleting them, but if you are deleting whole sheets, this may not be an option.

The problem has been around for a long time, apparently, and mainly strikes with charts.

Sorry I cannot give a more helpful reply other than: You're not alone.

cheers, teylyn
0
 

Author Closing Comment

by:developingprogrammer
ID: 38791958
ok no problem, but thanks for helping me confirm this teylyn!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question