private static void ResizeSelection(Excel.Application application, bool isRow, bool isIncrease) { if (application.ActiveWindow == null) { MessageBox.Show(UI_Resources.ResizeSelection_NoActiveWindow); return; } var source = CurrentSelection.RangeSelection(application); Excel.Range r1 = null; int increment = isIncrease ? 1 : -1; foreach (Excel.Range r2 in source.Areas) { int currentSize = isRow ? r2.Rows.Count : r2.Columns.Count; int size = increment + currentSize; if (size.Equals(0)) { MessageBox.Show(UI_Resources.ResizeSelection_LastRowColumnError); return; } //TODO: This section will still produce an error if the last column or row in a spreadsheet is trying to increase its size. if (r1 == null) { r1 = isRow ? r2.Resize[RowSize : size] : r2.Resize[ColumnSize : size]; } else { r1 = application.Union(r1, isRow ? r2.Resize[RowSize: size] : r2.Resize[ColumnSize: size]); } } r1.Select(); }