Error 6 — “Overflow” — means a calculation produced a number outside the range of the variable (or the intermediate type) meant to hold it. The classic case: an Integer variable asked to hold a row number above 32,767 in a modern spreadsheet. The math was fine; the container was too small.
VBA types have hard limits: Integer tops out at 32,767, Long at about 2.1 billion, Byte at 255, Single/Double at astronomically larger values. Overflow fires when a value crosses its container's limit — including mid-calculation: 20000 * 2 overflows if VBA does the multiplication in Integer space before the result reaches a Long variable.
CInt() — conversions overflow exactly like assignments.Dim i As Long is the house standard that deletes this error class.CLng(a) * b, or write constants with a type suffix (20000&).CLng() instead of CInt() when values can exceed 32,767 — and guard genuinely huge inputs when even Long isn't enough (then it's Double territory, with its precision trade-offs).If every declaration looks wide, the overflow is in a conversion or an API/property that itself uses a smaller type — check what the failing call expects (some older properties are Integer-typed no matter what you pass). Print intermediate results with Debug.Print walking up to the line; overflow always announces which quantity crossed which limit.
Why did old code start overflowing now? Data grew. Integers were safe when sheets had hundreds of rows and files were small; modern row counts and volumes crossed the 32,767 ceiling that was always there.
Integer or Long — does it matter for speed? On modern hardware, no meaningful difference. Long is the correct default for anything that counts rows, records, or bytes.