This code looks for the column with header "Quantity Dispensed," then convert the strings in the column by treating the right three digits as decimals, 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
I'm getting Overflow error on the line "x = Evaluate..." while executing.
The values in the column are in string form. e.g. "0000120000"
.
Dim x As Integer
toDim x As Long
. max value of integer is only 32768. Also it'd be more reliable to useDim i As Long
. Btw, is there any reason to usex = Evaluate(Cells(i, colNum).Value)
insteadx = Cells(i, colNum).Value
? – Dmitry Pavliv Apr 1 '14 at 20:10120000
greater than max value of integer32768
. UseLong
type instead. And there is no need to useEvaluate
– Dmitry Pavliv Apr 1 '14 at 20:21