Id'ing tabs that contain #REF!'s

S

Steve

I have a workbook with quite a few sheets, many having formulas that refer to
other sheets. Sometimes when I make changes to some of the cells in certain
sheets, I'll get #REF!'s on other sheets/cells. I'm thinking I'd like to have
a separate sheet that would show which sheets have #REF!'s., something like:

Sheet a! ok
Sheet b! Ref
Sheet c! Ref
Sheet d! ok

So I could easily goto that sheet and fix the #REF!.

Is that possible ?

Thanks,

Steve
 
P

p45cal

Well, perhaps:
You could have the likes of
=SUMPRODUCT(--ISERR(Sheet2!A1:Z400))
in a cell which will count the number of errors like
#VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or #NULL
(note #N/A is excluded).
Now it could be that you have already got errors which you know abou
on sheet2!1:Z400, so what you can do is change this a bit so that i
flags up only extra errors. So first enter the above formula (adjuste
for the correct range) to see how many pre-existing errors there ar
(let's say there are 3) then adjust the formula to:
=IF(SUMPRODUCT(--ISERR(Sheet2!A1:Z400))>3,"New Errors!","OK")

The only problem is if you have errors which are only converted fro
one form to #REF! they won't be flagged.

There is a macro solution which will definitely give you a solution
but if this one will do then I'm not going to bother to write one.
Come back if you really need one.




I have a workbook with quite a few sheets, many having formulas tha
refer to
 
S

Steve

I think this will work fine. It's even better than I requested because it's
counting the errors. And I don't think I'll need the new errors part.

One question though - is there somethinng like ISREF, which it'll only count
the Ref's ?

Also, I don't quite understand this:
The only problem is if you have errors which are only converted from
one form to #REF! they won't be flagged.


Thanks again,

Steve
 
P

p45cal

One question though - is there somethinng like ISREF, which it'll onl
count
the Ref's ?



Yes, there is 'ISREF', unfortunately it's nothing to do with errors!

Also, I don't quite understand this:


Because there's nothing to count specifically #REF! errors, the ISER
counts all errors (except #N/A), so if you had these errors on th
sheet: #NUM!, #DIV/0!, and #NUM!, there'd be 3 errors. If you then mak
your changes elsewhere and count the errors again, and you find ther
are still 3, you have no idea whether one or more of the existing error
had been changed to a #REF! error, because, for example
#REF!,#REF!,#NUM! still returns 3 errors. No increase in error count, s
you might feel comfortable that your changes hadn't introduced any ne
errors, although they really had.



I think this will work fine. It's even better than I requested becaus
it's
 
H

Harlan Grove

Steve said:
a separate sheet that would show which sheets have #REF!'s., something like:

Sheet a!    ok
Sheet b!    Ref
Sheet c!    Ref
Sheet d!    ok
....

If you want to identify worksheets which have cells evaluating to
#REF!, then with the worksheet name in cell A3, you could use the
formula

=IF(COUNTIF(INDIRECT("'"&A3&"'!A:IV"),"=#REF!"),"Ref","ok")

Note that such formulas recalculate very slowly. Since you wouldn't
need to do this often, you may be better off using a macro to list the
worksheets with cells evaluating to #REF!. Something like


Sub foo()
Dim ws As Worksheet, wsc As Sheets, res As String

If ActiveWindow.SelectedSheets.Count > 1 Then
Set wsc = ActiveWindow.SelectedSheets
Else
Set wsc = ActiveWindow.Parent.Worksheets
End If

On Error Resume Next
Debug.Print String$(40, "-")

For Each ws In wsc
Call ws.UsedRange _
.SpecialCells(xlCellTypeFormulas, xlErrors) _
.Find(what:="#REF!", LookIn:=xlValues)

If Err.Number = 0 Then
res = res & vbLf & ws.Name
Debug.Print ws.Name
Else
Err.Clear
End If
Next ws

On Error GoTo 0
Debug.Print String$(40, "-")

If res = "" Then res = "<none>" Else res = Mid$(res, 2)
MsgBox Title:="Worksheets with #REF! errors", Prompt:=res,
Buttons:=vbOKOnly

End Sub
 
P

p45cal

Well, I was making far too much of a meal of it. After Harlan'
suggestions,
change my formula:
=SUMPRODUCT(--ISERR(Sheet2!A1:Z400))
to:
=COUNTIF(Sheet2!A1:Z400,#REF!)
to get your count of just #Ref! errrors.




p45cal;703280 said:
Well, perhaps:
You could have the likes of
=SUMPRODUCT(--ISERR(Sheet2!A1:Z400))
in a cell which will count the number of errors like
#VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or #NULL
(note #N/A is excluded).
Now it could be that you have already got errors which you know abou
on sheet2!1:Z400, so what you can do is change this a bit so that i
flags up only extra errors. So first enter the above formula (adjuste
for the correct range) to see how many pre-existing errors there ar
(let's say there are 3) then adjust the formula to:
=IF(SUMPRODUCT(--ISERR(Sheet2!A1:Z400))>3,"New Errors!","OK")

The only problem is if you have errors which are only converted fro
one form to #REF! they won't be flagged.
There is a macro solution which will definitely give you a solution
but if this one will do then I'm not going to bother to write one.
 
R

Rick Rothstein

Keeping your output structure as is, couldn't you use this slightly simpler
For Each loop?

Sub Foo()
Dim WS As Worksheet, Res As String
Debug.Print String$(40, "-")
For Each WS In ActiveWindow.SelectedSheets
If Not WS.Cells.Find(What:="#REF!", LookIn:=xlValues) Is Nothing Then
Debug.Print WS.Name
Res = Res & vbLf & WS.Name
End If
Next
Debug.Print String$(40, "-")
If Res = "" Then Res = "<none>" Else Res = Mid$(Res, 2)
MsgBox Res, vbOKOnly, "Worksheets with #REF! errors"
End Sub
 
S

Steve

Thank you.

Works great.

p45cal said:
Well, I was making far too much of a meal of it. After Harlan's
suggestions,
change my formula:
=SUMPRODUCT(--ISERR(Sheet2!A1:Z400))
to:
=COUNTIF(Sheet2!A1:Z400,#REF!)
to get your count of just #Ref! errrors.





on sheet2!1:Z400, so what you can do is change this a bit so that it
flags up only extra errors. So first enter the above formula (adjusted
for the correct range) to see how many pre-existing errors there are
(let's say there are 3) then adjust the formula to:
one form to #REF! they won't be flagged.
but if this one will do then I'm not going to bother to write one.


--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: http://www.thecodecage.com/forumz/member.php?u=558
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=196733

http://www.thecodecage.com/forumz

.
 
S

Steve

I can't get the countif(indirect to work. It's producing a zero.

The macro is working, but it seems to only identify whether ref or not on
the sheet I'm on. I guess I have to go to each sheet and run the macro ?

Thanks,

Steve
 
S

Steve

Pretty slick. Thanks.
A few things:
I'm getting the hourglass hanging after running it.The only way to get rid
of it is to close the box or ESC.
Can the results be printed or copied to a section of a worksheet ?
It evalutas hidden sheets also. Is there a way to have it only look for
visible sheets ?
Is that a text reference to the "#ref!", meaning it's not only producing
results for the evaluated #Ref! but even if there happens to be #REF! as
text, correct ? Just curious.

Thanks again,

Steve
 
R

Rick Rothstein

1) The hour glass cursor is what Excel does while it is displaying a
MessageBox... I'm pretty sure you can't turn it off except to dismiss the
MessageBox.

2) You can output the contents of the Res variable anywhere you need it.
Harlan used a MessageBox and I decided to use his same output structure in
my code, hence, I also used a MessageBox. To put it in a cell, say for
example purposes on Sheet1 in Cell A1, just change the last line of code to
this...

Worksheets("Sheet1").Range("A1").Value = Res

3) As the code was structured, it looked as Selected Sheets only... how did
you select a hidden sheet? I guess if you are running this through a loop of
all sheets, you could change this line in the If...Then statement...

WS.Cells.Find(What:="#REF!", LookIn:=xlValues)

to this...

WS.Cells.SpecialCells(xlCellTypeVisible).Find(What:="#REF!",LookIn:=xlValues)

4) Yes, depending on what your last Find settings were, it *might* find
#REF!, #Ref!, #ref!, etc. as a text string within cells displaying text
containing those characters. I say "might" because Find has a "feature"
whereby it remembers the settings previously assigned to its arguments. So,
if you had previously set the LookAt argument to xlPart, then it would find
the text #REF! within a larger piece of text containing it. Whether if would
find the other cases (#Ref!, #ref!, etc.) would depend on the previous
setting for the MatchCase argument. I assumed that such text would not
appear in your cell's normal text strings, so I didn't account for it. We
could control it somewhat be changing my Find function reference in the
If..Then statement to this...

Find(What:="#REF!", LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True)

This would still find "#REF!" as a text string IF your user decided to type
that into a cell or if you had any formulas that returned that exact text
string (which, personally, I think would be a silly thing to do). However,
if even this is a possibility, then you would need to go with Harlan's code
as he restricts his search to only those cells that returned an error.
 
S

Steve

Thank you very much for the very thorough explanations.
I just had those sheets hidden, but your suggested fix now looks at only the
visible sheets.

Two last things:
Is there a way to put the list starting in A1 thru, e.g. A20. This currently
is putting the entire list in just A1, causing Row 1 to be very, very tall.
Also, it seems to be listing sheets that do not have #REF! in them. I did
searches for them thinking it had #REF!s, but the search resulted in no
#REF!s being found.
I also double-checked via this from Cal =COUNTIF(Sheet2!A1:Z400,#REF!) and
that also is showing no #REF!s.

Thanks again,

Steve
 
R

Rick Rothstein

I'm not sure what to tell you about finding #REF! errors on sheets that do
not have them... I cannot duplicate that result here. If you want to send
your workbook to me so that I can see it happen, then maybe I'll be able to
figure out why. If you choose to do this, just remove the NO.SPAM stuff from
my listed email address.

As for making the list print out in multiple cells, do the following...

Change the Dim statement to this...

Dim WS As Worksheet, Res As String, TempArray() As String

Then replace the last line of code with these lines...

TempArray = Split(Res, vbLf)
With Worksheets("Sheet1")
.Columns(1).Clear
.Range("A1").Resize(1 + UBound(TempArray)) = _
WorksheetFunction.Transpose(TempArray)
End With
 
S

Steve

Thanks. I just sent it to you.
Nicely putting names in the entire A column now, but still all sheets, not
just the #REF! sheets.

Thanks again,

Steve
 
S

Steve

I removed the No.SPAM in front of and after the @ but it got kicked back as
undeliverable.
 
R

Rick Rothstein

The address you should have sent it to was (minus the line feeds and
converting AT to @)...

rick.news
AT
verizon.net

Is that what you tried? I am getting email at that address, so it is
working. Try it again.
 
R

Rick Rothstein

Steve followed up with me via email and, to keep the archive complete, here
is the response I sent back to him...

The code seems to work as designed. The code, as written, is meant to be
called AFTER you select all the worksheets you want to apply it to (this
goes back to my follow up question asking how you were selecting your hidden
worksheets... you can't as far as I know). To select the worksheets, click
on the first one and then Shift-Click on the last one... you will see all of
the sheet tabs become the "selected color" indicating they are selected...
running the code now produces the list you wanted. I'm now guessing that you
don't want the macro to operate like this; rather, you just **always** want
to process **all** visible sheets. See if this modified macro does what you
want...

Sub Findrefs()
'
' Findrefs Macro
' Macro recorded 4/21/2010 by Steve

Dim WS As Worksheet, Res As String, TempArray() As String
If ActiveWindow.SelectedSheets.Count > 1 Then
Set wsc = ActiveWindow.SelectedSheets
Else
Set wsc = ActiveWindow.Parent.Worksheets
End If
On Error Resume Next
Debug.Print String$(40, "-")
For Each WS In wsc
If WS.Visible Then
Call WS.UsedRange.Find(What:="#REF!", LookIn:=xlValues)
If Err.Number = 0 Then
Res = Res & vbLf & WS.Name
Debug.Print WS.Name
Else
Err.Clear
End If
End If
Next WS
On Error GoTo 0
Debug.Print String$(40, "-")
If Res = "" Then Res = "<none>" Else Res = Mid$(Res, 2)
TempArray = Split(Res, vbLf)
With Worksheets("Refsheet")
.Columns(1).Clear
.Range("A3").Resize(1 + UBound(TempArray)) = _
WorksheetFunction.Transpose(TempArray)
End With

End Sub
 
R

Rick Rothstein

****Code Correction****

I just sent this to Steve...

The code I sent you just a little while ago does not seem to work correctly;
try this macro instead...

Sub Findrefs()
'
' Findrefs Macro
' Macro recorded 4/21/2010 by Steve
'
Dim WS As Worksheet, Res As String, TempArray() As String
On Error Resume Next
Debug.Print String$(40, "-")
For Each WS In ActiveWindow.Parent.Worksheets
If WS.Visible Then
Call WS.UsedRange.SpecialCells(xlCellTypeFormulas, xlErrors). _
Find(What:="#REF!", LookIn:=xlValues)
If Err.Number = 0 Then
Res = Res & vbLf & WS.Name
Debug.Print WS.Name
End If
Err.Clear
End If
Next WS
On Error GoTo 0
Debug.Print String$(40, "-")
If Res = "" Then Res = "<none>" Else Res = Mid$(Res, 2)
TempArray = Split(Res, vbLf)
With Worksheets("Refsheet")
.Columns(1).Clear
.Range("A3").Resize(1 + UBound(TempArray)) = _
WorksheetFunction.Transpose(TempArray)
End With

End Sub
 
S

Steve

By just running it without selecting any WS's, it lists every worksheet in
the file.
By selecting all the WS's, it does list only a few, but it is overlisting
them, meaning, it lists WS's without the #REF! in them. It's probably my
file. It's over 19KB in size, and I've had weird things happen with it before
that don't seem to make sense, so this could be one of those situations. I do
appreciate all you efforts, like I said, it's probably the file.

Thanks again for all your patience,

Steve
 
S

Steve

Getting VERY close.
But in addition to the #REF!s it's also listing sheets that have #N/A.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top