Run-time error 6 in VBA is the Overflow error. This means that a variable has been declared as one numeric data type, and then populated with a number that is outside the parameters of that data type. Consider the following code:
We are declaring i as an Integer variable. An integer variable can hold the values of ‑32,768 to 32,768. We are trying to assign the value of 600,000, which is outside the allowed range and therefore the error will occur. If we click on Debug when this error occurs, the error line will appear in yellow. To solve this error, make sure you declare the variable with the correct numeric data types to hold the required data: In this case use the Long Variable type.
We recommend always using the Long variable type instead of the Integer variable type. The only advantage of the Integer variable type is less memory is required. However, this is mostly irrelevant for coding running from VBA on modern computers. I am a Programmer but never use VBA. I am taking over someone's old script and it keeps failing at a certain point with a Run-Time Error. The Debugging report is here: Please let me know if you need more code. I have tried to change currRow to Long, single, double, string none work. Below is a quick glimpse of the sheet that is failing. The top row is row one. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Overflow (Error 6)
In this articleAn overflow results when you try to make an assignment that exceeds the limitations of the target of the assignment. This error has the following causes and solutions:
For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh). Support and feedbackHave questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback. 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.
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. Understanding of data types and their range of values to store can help you correct this error. It can also help you to not to write a code in way which runs in the Overflow error. |