4

I think Excel is going senile.

For the life of me, I can't get my Excel VBA macro to ignore a "Number Stored as Text" error.

In cell C71 on a worksheet called "Main," I have the value 6135413313, which Excel is warning is a number stored as text. And it should be. But I want to remove that annoying little triangle at the end of my macro.

I've reduced my macro code to the bare bones for testing purposes, but that triangle still persists. Here's my macro:

Sub test()
    Range("C71").Errors(xlEvaluateToError).Ignore = True
End Sub

How is this not making that error go away? I've also tried Range("Main!C71"). That didn't work either.

This should be mind-bogglingly easy, but that one line of code still doesn't work. Any ideas?

4
  • Range is implicitly working on the ActiveSheet. Is that your intention? Commented Apr 28, 2017 at 1:28
  • 1
    I suspect that the Range.Errors property is read-only. (The documentation says it returns something, but doesn't say you can set anything.) I think you are looking for Application.ErrorCheckingOptions.NumberAsText = False Commented Apr 28, 2017 at 1:29
  • Did either of the answers solve your query? If so, please mark them appropriately to close this question. Commented Jul 22, 2017 at 8:31
  • Sorry. Yes it did. Marked. Commented Aug 5, 2017 at 16:07

3 Answers 3

2

you can try this

Sub test()
Sheets("Main").Range("C71").Errors(xlNumberAsText).Ignore = True
End Sub

or

Sub test()
Sheets("Main").Range("C71").Value = Sheets("Main").Range("C71").Value
End Sub

or

The other way is you can manually disable background error checking.
you can find this option by clicking File - Excel Options - Formulas and uncheck the option

it will disable error checking for all cells

background error checking

Sign up to request clarification or add additional context in comments.

Comments

1

"Selection.Errors(xlTextDate).Ignore = True" will not work. To correct replace (xlTextDate) with one of the following values

  • (3)
  • (xlTextDate)
  • (xlNumberAsText - 1)

However, check the various values as your version of Excel may be different. I am using Excel 365.

Source: https://learn.microsoft.com/en-us/office/vba/api/Excel.XlErrorChecks On that page every variable list the needed value but not what Excel has assigned.

  • "Variable", "reported/needed", "Actual Excel Value"
  • xlEmptyCellReferences, 7, 8
  • xlEvaluateToError, 1, 2
  • xlInconsistentFormula, 4, 5
  • xlInconsistentListFormula, 9, 10
  • xlListDataValidation, 8, 9
  • xlNumberAsText, 3, 4
  • xlOmittedCells, 5, 6
  • xlTextDate, 2, 3
  • xlUnlockedFormulaCells, 6, 7

I don't make up the rules! When the values are corrected our code will likely fail again. I would report but MS has never fixed an error I have reported.

Reason to use text format: storing Facebook Video Id "4592884094151437" becomes "4592884094151430" doesn't work.

2 Comments

Maybe it's only an issue in the 365 version, I had the same problem, it is not mentioned anywhere in older code snippets. Costed 2 hours of my life, so thank you for sharing this.
Your welcome. It could be a bug that only exists in 365 but I would be surprised if it was. They added three more XLErrorChecks at some point. 01 xlStaleValue (aka the culprit) 11 XlMisleadingFormat 12 XlOutdatedLinkedDataType
0

Cycling through each cell in the range to test the xlNumberAsText error and set the ignore flag works (although if you have a large number of cells, this may be slow).

Sub test2()
    Call turnOffNumberAsTextError(Sheets("Main").Range("C71"))
End Sub

Sub turnOffNumberAsTextError(rge As Range)
    Dim rngCell As Range
    For Each rngCell In rge.Cells
        With rngCell
            If .Errors.Item(xlNumberAsText).Value Then
                .Errors.Item(xlNumberAsText).Ignore = True
            End If
        End With
    Next rngCell
End Sub

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.