Custom number format in Excel for error messages

jdcrowley

New Member
Joined
Jan 27, 2006
Messages
5
Hi everyone,

Is there a custom number format that will recognize whether a cell has an error (#NA or DIV0, etc ... ) and replace it with a text string?

I would like to prepare a table that looks nice. That means it can't have things like #NA in it. Errors have to be replaced with something pretty, like "...". But I don't want to type over my formulas with "..." because when I correct the input cell I will likely forget that I also have to go fix my table. I would prefer that Excel do this for me automatically.

I can do it with a formula that has something like =IF(ISERR(A15),"...", A15), but that is tedious to type into every cell. It would be much easier if I could just create a custom number format to solve the problem.

Thanks.
 
1.
you could use a button with some actions
make copy of sheet
hide it
rename it
visible sheet gets name of original
apply code to set errorformulas

when done click button to delete sheet
unhide original sheet and rename to original name

a bit overkill ?

2.
you could hide hide the formulas (see cellproperties/protection tab)
then protect sheet
no confusion about formulas since nobody can see them ...
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Perhaps this :-

Code:
Sub Remove_ISERROR_From_Formulas()
Dim rng As Range, cell As Range, fmla As String, f%
If TypeName(Selection) <> "Range" Then
    MsgBox "Select one or more worksheet cells."
    Exit Sub
End If
On Error Resume Next
If Selection.Cells.Count = 1 Then
    If Selection.HasFormula Then
        If Left(Selection.Formula, 10) = "=IF(ISERROR" Then
            f = InStr(Selection.Formula, "...")
            fmla = Right(Selection.Formula, Len(Selection.Formula) - 1)
            Selection.Formula = "=" & Mid(Selection.Formula, f + 5, Len(Selection.Formula) - f - 5)
        End If
    End If
    GoTo e
End If
Set rng = Selection.SpecialCells(xlCellTypeFormulas, 23)
If rng Is Nothing Then GoTo e
For Each cell In rng
    If Left(cell.Formula, 10) <> "=IF(ISERROR" Then
        f = InStr(cell.Formula, "...")
        fmla = Right(cell.Formula, Len(cell.Formula) - 1)
        cell.Formula = "=" & Mid(cell.Formula, f + 5, Len(cell.Formula) - f - 5)
    End If
Next
e:
On Error GoTo 0
End Sub
 
Upvote 0
Actually, if I could change them back it would be a slight advantage since the next person who works on my table is going to freak out if they see that formula.
-jdcrowley
IMHO you're better off leaving them as formulae if the inputs will ever be altered back to statuses where you can expect errors again. If you want to keep the in-cell formulae looking as pretty as possible you can edit Erik's bit of code a bit to where it simply wraps the formulae in a wee UDF wrapper. Let's name our wrapper e() to keep it as short as possible. Taking Erik's code as our starting point:
Code:
Sub EditFormulae()
' Based on code from Erik van Geit
    Dim rngCell As Range, strFormula As String
    For Each rngCell In ActiveSheet.Cells.SpecialCells(xlCellTypeFormulas)
        With rngCell
            strFormula = Mid(.Formula, 2)
            .Formula = "=e(" & strFormula & ")"
        End With
    Next rngCell
End Sub
Now your in-cell formulae simply read<ul>[*]=e(originalformula)[/list]The miniature wrapper UDF is just one line of code:
Code:
Public Function e(varInput As Variant) As Variant
    e = IIf(IsError(varInput), "...", varInput)
End Function
That would keep your in-cell formulae neat and tidy and relatively easy to edit should you need to do so.
 
Upvote 0

Forum statistics

Threads
1,216,058
Messages
6,128,538
Members
449,456
Latest member
SammMcCandless

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top