Sub DoSomething()
Dim row As Integer
For row = 1 To 100000
'do stuff
Next
End Sub
The Integer
data type is a 16-bit signed integer with a maximum value of 32,767; assigning it to anything larger than that will overflow the type and raise this error.
Sub DoSomething()
Dim row As Long
For row = 1 To 100000
'do stuff
Next
End Sub
By using a Long
(32-bit) integer instead, we can now make a loop that iterates more than 32,767 times without overflowing the counter variable's type.
See Data Types and Limits for more information.