Do While - 溢出错误

时间:2014-04-01 20:09:06

标签: vba

此代码查找标题为“Quantity Dispensed”的列,然后通过将右边的三位数视为小数来转换列中的字符串,e.i。 00009102" = 9.102

Sub ConvertDec()
Dim colNum As Integer
Dim i As Integer
Dim x As Integer

colNum = WorksheetFunction.Match("Quantity Dispensed", ActiveWorkbook.ActiveSheet.Range("1:1"), 0)
i = 2

Do While ActiveWorkbook.ActiveSheet.Cells(i, colNum).Value <> ""
    x = Evaluate(Cells(i, colNum).Value)
    Cells(i, colNum) = Int(x / 1000) + (x Mod 1000) / 1000
    i = i + 1
Loop

End Sub

执行时,“x =评估...”行出现溢出错误。

列中的值采用字符串形式。例如"0000120000"

1 个答案:

答案 0 :(得分:1)

  

120000大于整数32768的最大值。请改用Long类型。

Simoco