An overflow may happen if VBA is using int
as datatype and an intermediate result exceeds the size of an int
- even if the final result is small enough to fit into an int
Dim i As Integer
i = 1000 * 1000 / 2000 ' Will raise overflow
You should force VBA to use datatype long
.
So instead of using function val
, use function CLng
.
Dim i As Integer
i = CLng(1000) * 1000 / 2000 ' Okay
i = CLng("1000") * CLng("1000") / cLng("2000") ' Okay
As YowEwK statet, this maybe doesn't solve your issue. If not, define a variable for every value you are dealing with (as long
or double
), assign the value f the label to it and check the values of them in the debugger if the runtime error still happens:
Dim val27 As doubble
Dim val19 As doubble
val27 = Val(Label27)
val9 = Val(Label9)
...
BTW: You should consider to name all your fields and variables with something meaningful. And do not forget to add Option explicit