J
jln via OfficeKB.com
How can i in code find alll cells that have #Ref! and replace it with 0?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Dave Peterson said:Another option based on Brian's suggestion:
Cells.Replace What:="*#REF!*", _
Replacement:="0", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False
Tom said:I mean I ran your code and it did nothing for me in a worksheet where #REF!
is produced by a formula. Replace looks at the formula in the cell
=someformula
and #REF! will not be found there unless someone has something goofy like
=if(True,"#REF!",";-)")
xl2003
I ran your macro on my sheet and got
#REF! #REF! #REF! #REF! #REF!
#REF! #REF! #REF! #REF! #REF!
#REF! #REF! #REF! #REF! #REF!
#REF! #REF! #REF! #REF! #REF!
#REF! #REF! #REF! #REF! #REF!
0 0 0 0 0
#REF! #REF! #REF! #REF! #REF!
#REF! #REF! #REF! #REF! #REF!
#REF! #REF! #REF! #REF! #REF!
#REF! #REF! #REF! #REF! #REF!
#REF! #REF! #REF! #REF! #REF!
#REF! #REF! #REF! #REF! #REF!
#REF! #REF! #REF! #REF! #REF!
Guess which row I had done Edit=>Copy, then Edit=>Paste Special, then
values.
Maybe we are talking apples and oranges - enlighten me on "What I am
missing" as you might say. Because of your great wisdom, I hesitate to
question your suggestion, but in this case, I don't see it.
I put a bunch of formulas starting in D6:
=A1+B1+C1 =B1+C1+D1 =C1+D1+E1
=A2+B2+C2 =B2+C2+D2 =C2+D2+E2
=A3+B3+C3 =B3+C3+D3 =C3+D3+E3
=A4+B4+C4 =B4+C4+D4 =C4+D4+E4
=A5+B5+C5 =B5+C5+D5 =C5+D5+E5
Then I deleted column A and row 1:
My formulas changed to:
=#REF!+#REF!+#REF! =#REF!+#REF!+#REF! =#REF!+#REF!+#REF!
=#REF!+A1+B1 =A1+B1+C1 =B1+C1+D1
=#REF!+A2+B2 =A2+B2+C2 =B2+C2+D2
=#REF!+A3+B3 =A3+B3+C3 =B3+C3+D3
=#REF!+A4+B4 =A4+B4+C4 =B4+C4+D4
=#REF!+A5+B5 =A5+B5+C5 =B5+C5+D5
And then ran that line of code. My formulas that were broken were changed to
0's.
I also used xl2003.
And I tested a few times before my original post--and a couple times with this
one.
Maybe it was a differences in the type of broken formulas we used???
And when it comes down to wisdom, I'll defer to yours <bg>.
Tom said:Assuming that would be the only error in the cells selected:
On Error Resume Next
Selection.SpecialCells(xlFormulas,xlErrors) = 0
On Error goto 0
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.