Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 504
Default Checking reference for named cells

If I have several named cells in say 10 worksheets, and I delete sheet 8,
then I have some named ranged left out there with no valid reference.

How can I check the validity of a named cell in vba? I have this so far...

Sub test()
Dim Nam As Name
For Each Nam In ActiveWorkbook.Names

"Place code here to check if reference on name is good, if it isnt then
delete that name."

Next Nam
End Sub

Thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Checking reference for named cells

Kevin,

Excel will automatically delete the name - it is the dependent cells formulas that will error out.
Try the macro below to find the #REF! errors.

HTH,
Bernie
MS Excel MVP

Sub FindMissingNameReferences()

Dim mySht As Worksheet
Dim myCell As Range
Dim err As String

For Each mySht In ActiveWorkbook.Worksheets
On Error GoTo NoErrs
For Each myCell In mySht.Cells.SpecialCells(xlCellTypeFormulas, 16)
err = CStr(myCell.Value)
If err = "Error 2023" Then
MsgBox myCell.Address(, , , True) & _
" has a reference to a missing name."
End If
Next myCell
NoErrs:
Resume nextSheet
nextSheet:

Next mySht
End Sub


"Kevin" wrote in message
...
If I have several named cells in say 10 worksheets, and I delete sheet 8,
then I have some named ranged left out there with no valid reference.

How can I check the validity of a named cell in vba? I have this so far...

Sub test()
Dim Nam As Name
For Each Nam In ActiveWorkbook.Names

"Place code here to check if reference on name is good, if it isnt then
delete that name."

Next Nam
End Sub

Thanks in advance



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Checking reference for named cells

For Each Nam In ActiveWorkbook.Names
If Left(Nam.Value, 5) = "=#REF" Then
'put your code here
End If
Next Nam

"Kevin" wrote:

If I have several named cells in say 10 worksheets, and I delete sheet 8,
then I have some named ranged left out there with no valid reference.

How can I check the validity of a named cell in vba? I have this so far...

Sub test()
Dim Nam As Name
For Each Nam In ActiveWorkbook.Names

"Place code here to check if reference on name is good, if it isnt then
delete that name."

Next Nam
End Sub

Thanks in advance

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 504
Default Checking reference for named cells

:) thanks Joel, that is exactly what I came up with while poking around..

If Left(Nam, 5) = "=#REF" Then
Nam.Delete
End If

Bernie, I would think that if you deleted a sheet that the names would be
deleted also, but when I go to INSERT-NAME-DEFINE, they are still listed jst
with bad references. This was making other macros I had mess up as it was
still going through old names and giving me bogus values..

This will work for though... Thanks guys!!!

"Joel" wrote:

For Each Nam In ActiveWorkbook.Names
If Left(Nam.Value, 5) = "=#REF" Then
'put your code here
End If
Next Nam

"Kevin" wrote:

If I have several named cells in say 10 worksheets, and I delete sheet 8,
then I have some named ranged left out there with no valid reference.

How can I check the validity of a named cell in vba? I have this so far...

Sub test()
Dim Nam As Name
For Each Nam In ActiveWorkbook.Names

"Place code here to check if reference on name is good, if it isnt then
delete that name."

Next Nam
End Sub

Thanks in advance

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Checking reference for named cells

Sorry - I mis-read your post, and was thinking about the error raised when a block of cells
containing a named range is deleted.

Bernie
MS Excel MVP


"Kevin" wrote in message
...

Bernie, I would think that if you deleted a sheet that the names would be
deleted also, but when I go to INSERT-NAME-DEFINE, they are still listed jst
with bad references. This was making other macros I had mess up as it was
still going through old names and giving me bogus values..





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking for non-blank cells in named range Barb Reinhardt Excel Programming 2 October 13th 06 06:34 PM
Checking for non blank cells in named range Barb Reinhardt Excel Programming 1 October 13th 06 03:32 PM
Checking for non-blank cells in named range Barb Reinhardt Excel Programming 0 October 13th 06 02:42 PM
3 cells are named together - how refere to them in one chart reference field (a seriescollection(1) ) Marie J-son[_4_] Excel Programming 3 December 2nd 04 08:36 PM
3 cells are named - how to refere to them in one reference field in a chart Marie J-son Charts and Charting in Excel 2 December 2nd 04 04:52 PM


All times are GMT +1. The time now is 09:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"