溢出警告VBA

运行下面的代码片段时,我得到溢出警告:

For Each Row In Rng.Rows For Each cell In Row.Cells cell.Activate ActiveCell.Select If IsNumeric(ActiveCell) Then ActiveCell.Value = CInt(ActiveCell.Value) End If Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _ Formula1:="=1" Selection.FormatConditions (Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior.ColorIndex = 20 End With Selection.FormatConditions(1).StopIfTrue = False Next cell Next Row 

单元格和行都声明为Variant。

代码是由别人写的,警告不是我的系统。 这个错误正在其他几个系统中出现。

请让我知道,如果有代码中的错误或任何其他方式停止得到这个消息。

该行发生错误:

 ActiveCell.Value = CInt(ActiveCell.Value) 

CInt只能处理-32,768到32,767之间的值。
检查你的数据types,找出哪一个更适合你的需求

试试这个。 避免使用Select语句。 它可能会导致很多错误(这是我怀疑是造成你的)。 另外,你不需要两个循环来实现这一点

 For Each cell In rng.cells If IsNumeric(cell) Then cell.Value = CLng(cell.Value) With cell .FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=1" .FormatConditions(.FormatConditions.Count).SetFirstPriority .FormatConditions(1).Interior.ColorIndex = 20 .FormatConditions(1).StopIfTrue = False End With Next cell