Example
option explicit
sub main() ' {
dim ws as worksheet
set ws = activeWorkbook.worksheets.add
ws.cells(1, 1).value = 43870.51
ws.cells(1, 2).formulaR1C1 = "= RC[-1]"
ws.cells(2, 1).value = 43970.920347
ws.cells(2, 2).value = #2020-05-19 22:05:18#
ws.cells(1, 2).numberFormat = "yyyy-mm-dd hh:mm:ss"
checkForMisleadingFormat ws
end sub ' }
sub checkForMisleadingFormat(ws as worksheet) ' {
dim c as range
for each c in ws.usedRange ' {
if c.errors(xlMisleadingFormat).value then ' {
debug.print("Misleading format error found in " & c.address)
end if' }
next c ' }
end sub ' }
When run, the debug.output
statement prints
Misleading format error found in $B$1
Ignoring errors in the immediate window
I find it easier to ignore errors with the
immediate window instead of using the mouse:
activeCell.errors(xlInconsistentFormula).ignore = true
It's also possible to first select the cells where the errors should be ignored and then to iterate over them:
for each for each c in selection: c.errors(xlNumberAsText).ignore = true: next c