Excel 会检测公式是否与表中的计算列不一致,并用绿色小三角形显示它们(表示“此单元格与列公式不一致”)。我怎样才能通过VBA找到它们。我发现这段代码应该可以解决这个问题(来自 http://www.ozgrid.com/forum/showthread.php?t=145306 ),但这仅在使用的范围是正常范围而不是表格时才有效:
Dim oneCell As Range
For Each oneCell In ActiveSheet.UsedRange
If oneCell.Errors(xlInconsistentFormula).Value Then
oneCell.Interior.ColorIndex = 6
Else
oneCell.Interior.ColorIndex = xlNone
End If
Next oneCell
但是 oneCell.Errors(xlInconcientFormula).Value
仅发送“False”,因此不起作用。
是否可以修复此问题以在表格而不是正常范围内工作?
编辑:如果您在表中工作,xlInconcientFormula 不会执行任何操作。
最佳答案
这有效:
Sub fhdjksjdfhs()
Dim r As Range
Dim rBig As Range
Set rBig = ActiveSheet.UsedRange.Cells.SpecialCells(xlCellTypeFormulas)
For Each r In rBig
If r.Errors.Item(xlInconsistentFormula).Value = True Then
r.Interior.ColorIndex = 6
Else
r.Interior.ColorIndex = xlNone
End If
Next r
End Sub
编辑#1:
正如Kersijus正确指出的那样,将一列或一组列转换为表可以抑制引发绿旗的错误检查级别。此代码不会检测以这种方式抑制的错误。
关于vba - 通过VBA查找Excel中不一致的公式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24511585/