Sub 隐藏所有错误值()
Dim rng As Range, cell As Range
On Error Resume Next '防錯,避免找不到錯誤值時產生錯誤
With ActiveSheet.UsedRange '僅對己用區域進行定位
Set rng = .SpecialCells(xlCellTypeFormulas, 16) '將公式結果為錯誤的區域賦值給變量RNG
If Err.Number = 0 Then '如果無錯誤(有錯誤公式)
Set rng = Union(rng, .SpecialCells(xlCellTypeConstants, 16)) '將非公式的錯誤單元格與變量RNG合併
Else '否則將常量錯誤單元格賦值給變量RNG
Set rng = .SpecialCells(xlCellTypeConstants, 16)
End If
Application.ScreenUpdating = False '並閉屏幕更新,加快速度
For Each cell In rng '遍歷所有錯誤單元格
cell.Font.Color = cell.Interior.Color '將字體色設置為背景色
Next
Application.ScreenUpdating = True '恢復屏幕更新
End With
End Sub