I know a similar question has been answered here:
What is the maximum value for row and column Range offset in VBA/Excel?
However, that error seemed to be related to the number of rows in the worksheet in Excel 2003. Since I am running Excel 2010 (with 65,536 rows), I don't think my error is related to my worksheet size.
Here is the line of code that is giving me Run-time error '6' Overflow:
Range("OutputStart").Offset(1 + (iCounter1 - 1) * iDataPoints * 26 + iCounter2 * iDataPoints, 0).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
iCounter1 is an integer and its value is 13 iDataPoints is an integer and its value is 103 icounter2 is an integer and its value is 7
The result of the row offset calculation is 32,858, which indicates an Integer data type issue. Is the row offset limited to Integer data types? If so, is there any way to change that limitation to Long (or another data type)?
Thanks for any help you can provide!
Will
Range.Offset method is not limited to integer.
Numeric data in Variant:
Integers in VB are 16 bit. Use an unsigned int; or more ideally, a long.
Range takes optional variants as arguments, and numeric data is preserved if that's what is fed into it.
To cast a number as a long, just wrap it in the
CLng(yournumber)
, or if your number gets huge, cast as a double withCDbl(yournum)
.Don't use Integer: they are 16 bit signed values; their range is -32768 to 32767. That is why you're getting the overflows.
Use a Long instead.