Found an interesting integer overflow condition today, thought I would share in case anybody else runs into same issue.
The condition arises when you use a literal int as the test expression in a Select Case statement:
Sub ProducesSelectCaseOverFlowWhenTooManyRowsSelected() Select Case 2 Case Selection.Rows.Count 'Do stuff here Case Selection.Columns.Count 'Do stuff here Case Selection.Areas.Count 'Do stuff here End Select End Sub
When the Selection.Rows.Count is larger than maximum 16-bit integer value 32,767, the "Case Selection.Rows.Count" line throws an overflow error.
I don't know how the compilation of Select Case constructs to p-code is implemented, but obviously each statement is evaluated in the (assumed) data type of the test expression.
The fix is easy: use a 32-bit integer (Long) constant as the test expression