I have some vba behaviour that I do not understand. I'm running vba in a macro of excel 2016.
Sub alpha()
Dim a As Integer, b As Long
a = 750
b = 50 * a
Stop
End Sub
Running this sub results in an overflow error. Why?
Variable a
is an integer and therefore cannot hold the number 750*50
because that is too high. But variable b
is dimensionalised as a long - so it should be able to hold that number.
Strangely - If I change the type of variable a
to Long
then the code runs through.