Solved

suppressing Excel invalid reference error message

Posted on 2012-12-27
5
511 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

Expert Comment

by:Ingeborg Hawighorst
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 46

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 earned 500 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

828 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