logo
search
Excel Error Codes

How to Fix VBA Run-Time Error 6 Overflow in Excel

Maira MehtabMaira Mehtab Sep 20, 2026 869 views

Question details

The user encounters a Run-time error 6 (Overflow) in an Excel VBA macro when attempting to assign a large date-coded serial number to a Long variable.

Product
Excel VBA
Device & OS
not provided
Scenario
Running an Excel VBA macro that processes large date-coded serial numbers (e.g., 2408070132).
Observed behavior
The VBA macro crashes and displays 'Run-time error 6: Overflow' because the assigned value exceeds the maximum capacity of a Long data type.
Before you start

Before modifying your VBA code, verify the exact variable that triggers the error by clicking 'Debug' on the error prompt to highlight the problematic line in your script.

Solution 1Recommended

Change the Variable Data Type to Double

Use this solution if you need to perform mathematical calculations on the serial number.

The maximum value for a Long data type in VBA is 2,147,483,647. The value 2,408,070,132 exceeds this limit, causing the numeric overflow. Changing the variable to a Double allows it to hold significantly larger numbers required for your operations.

1
Open the VBA Editor

Open your Excel workbook and press Alt + F11 to launch the Visual Basic for Applications (VBA) Editor.

2
Locate the problematic declaration

Find the macro module and locate the line where the variable causing the overflow (e.g., head_sn) is declared as 'Long'.

3
Modify the data type

Change the declaration from 'Dim [variable_name] As Long' to 'Dim [variable_name] As Double'.

4
Test the macro

Save the changes and run the macro again to confirm the overflow error is completely resolved.

Alternative Data Type: You can also use the 'Currency' data type if you need exact precision without the risk of floating-point rounding errors for extremely large integers.
Powerful Macro Support in WPS Office

Fix VBA Errors and Run Macros Seamlessly in WPS Office

WPS Office provides robust support for VBA and macros. You can easily edit your macro code, change variable types to fix overflow issues, and run complex scripts efficiently just like you do in Microsoft Excel.

  1. 1. Open your macro file: Open your macro-enabled spreadsheet (.xlsm) in WPS Spreadsheet.
  2. 2. Access the Macro Editor: Go to the 'Tools' tab on the top ribbon and click on 'Macro' to open the built-in VBA Editor.
  3. 3. Locate the error: Find the module with the Overflow error highlighted during debugging.
  4. 4. Apply the fix: Change the problematic 'Long' variable to 'Double' or 'String' and save your code.
  5. 5. Run the script: Click 'Run' directly from the editor to verify the fix works flawlessly.
Fully compatible with Microsoft Excel (.xlsm, .xls) macro formats.Built-in VBA editor to easily debug and troubleshoot Overflow errors.Free and lightweight alternative to Microsoft Office.Familiar interface for writing, testing, and editing macro scripts.
microsoft office alternative - wps office

Frequently Asked Questions

What does Run-time error 6 'Overflow' mean in Excel VBA?

This error occurs when you try to assign a value to a variable that exceeds its designated maximum capacity. For instance, assigning a number larger than 2,147,483,647 to a 'Long' variable triggers this overflow because it surpasses the memory limit for that specific data type.

What is the maximum value for an Integer data type in VBA?

The 'Integer' data type in VBA can only hold values up to 32,767. If your number exceeds this limit, you must declare the variable as a 'Long'. If it subsequently exceeds the 'Long' limit, you should use 'Double' or 'Currency'.

Can I ignore Run-time error 6 in my macro?

No, an overflow error is a critical execution error that will immediately halt the progress of your macro. You must modify your VBA code by changing the variable's data type to ensure it can accommodate the larger values.

Does WPS Office support Excel VBA macros?

Yes, WPS Office provides excellent support for VBA macros. Users can seamlessly run, edit, and debug scripts created in Microsoft Excel without compatibility issues, utilizing a familiar Macro Editor interface.