In my current version of Excel, the enumeration of xlNumberAsText seems inconsistent with both the documentation XlErrorChecks Enumeration (Excel) and prior usage recommended on SO. It seems that particular error is Item 4; whereas previous posts about clearing this error using VBA have used a constant of 3.
Is this a bug in Excel 2016? Or am I doing something incorrectly.
Here is code demonstrating the issue. And if you examine the worksheet after running the code, it is apparent that the error is flagged, in Excel, as NumberAsText
and not as Inconsistent Formula
.
Option Explicit
Sub foo()
Dim I As Long
Dim B As Boolean
Dim S As String
Dim R As Range
'Save current state
B = Application.ErrorCheckingOptions.NumberAsText
'Enable
Application.ErrorCheckingOptions.NumberAsText = True
Set R = Cells(1, 1)
With R
.Clear
.NumberFormat = "@"
.Value = "1"
End With
For I = 1 To 10
S = S & vbLf & I & vbTab & R.Errors(I).Value
Next I
S = Mid(S, 2)
'Restore original state
Application.ErrorCheckingOptions.NumberAsText = B
MsgBox S
End Sub
And also, in trying to clear the error box, I must use
R.Errors(4).Ignore = True
Neither Errors(3)
, nor Errors(xlNumberAsText)
will have any affect on the error box.
I've noted other inconsistencies with the enum and the documentation:
Inconsistent Formula: 5
Wrong Data Type: 2
I'm not going to bother to check the rest. But I am going to try to report it to MS. Thanks to those who confirmed this problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.