In VBA, Overflow (Error 6) is a run-time error that occurs when you specify a number to the variable that is out of the range of numbers which that data type can take. In simple words, this error occurs when you go out of the range for a variable’s type.
Let’s say you are using the Integer data type that can take values ranging from -32,768 to 32,767 so when you specify a value that is out of this range you get the Overflow run time error.
In the above example, you can see that we have used the integer data type for the iNum variable but while specifying the value we have used “10000000” which is way more than the range, and when you run the code Overflow run-time error occurs.
Sub myMacro()
Dim iNum As Integer
iNum = 10000000
End Sub
How to Deal with Overflow (VBA Error 6)
The way to deal with this error is to have a complete understanding of the VBA Data Types that you need to use while declaring a variable. You need to deal with a range of values when you are using a data type to store a numeric value in the variable. So, you need to examine the range of the result that you want to store in the variable.