You get overflow because Integer in VBA is a 16-bit subscription number (maximum value 32767). Regardless of the excel version, you have a minimum of 65535 lines and most likely more if you use the XLSX file format. You need to change rowNumber to Long
And you also need to copy around an empty sceneio sheet. When you call this line:
rowNumber = .Cells(2, 1).End(xlDown).End(xlDown).Row + 1
and the worksheet is empty, .End(xlDown) will return the last possible row in the worksheet, which in the case of Excel 2010 (and Excel 2007) is 1048576. After changing rowNumber to Long you will no longer receive an overflow error, but you will encounter a problem with this line:
.Rows(rowNumber & ":" & .Rows.Count).Clear
This is because you are trying to select a range (line 1048577) that does not exist (hence a type mismatch). You need to add a line of code to get around this scenario. Either check the blank sheet first, or check the line> 1048576.
The easiest way is to simply add a line to check this:
If rowNumber <= 1048576 Then .Rows(rowNumber & ":" & .Rows.Count).Clear End If
source share