Show “Number stored as Text” error

心不动则不痛 提交于 2019-12-31 04:09:13

问题


I'm using an Advanced Filter, among others, with 0 and 1's. The filter works correctly only if in the Data sheet the cells with 1 and 0 have the error message "Number stored as text" displayed. For that I have to manually open the cell with double click and press Enter. Then the error message appears and the filter works. If I don't do that, the filter doesn't work.

Alternatively I can click on the cell with 1 or 0 and press F2 to display the error message.

Is there a way with VBA that I can automatically do that?

Many thanks for your help!


回答1:


You'll find that buried deep in the Range properties for the cells, specifically in the Errors collection. Just find the cells where that error is present, then set the Ignore property to True:

Public Sub IgnoreNumsAsText()
    Dim current As Range
    For Each current In ActiveSheet.UsedRange.Cells
        With current
            If .Errors.Item(xlNumberAsText).Value = True Then
                .Errors.Item(xlNumberAsText).Ignore = True
            End If
        End With
    Next current
End Sub


来源:https://stackoverflow.com/questions/36157512/show-number-stored-as-text-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!