Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Problem with too large a range
Range.Address is limited to 255 characters. As you suspected the Union
method is not so contsrained, at least not until you get to very large multiarea ranges when things slow down. Sub test() Dim rw As Long, nCols As Long Dim rng As Range, rTriangle As Range Dim sq As Long side = 50 ' adjust for testing Set rng = Range(Cells(2, 2), Cells(2 + side, 2 + side)) ' validate it's a square range not included in this test ' make triangle starts here nCols = rng.Columns.Count Set rTriangle = rng.Rows(1) For rw = 2 To rng.Rows.Count Set rTriangle = Union(rTriangle, _ rng.Rows(rw).Resize(1, nCols - rw + 1)) Next rTriangle.Select End Sub Regards, Peter T "fullers" wrote in message ... I have the macro below that is run after a user highlights a square block of data (25 rows by 25 columns for example) and it then selects those cells that form the upper left triangle within the square. The problem I am having is if more than about 35 rows/columns are highlighted I get an error message. I believe I would need to modify my code to include the Union() command but not sure how to do this. Any help would be most appreciated. Sub HighlightUpperLeftTriangle() Dim FirstRow, FirstColumn, RowCount, ColumnCount, LastRow, LastColumn, x As Long Dim RangeSelect As String Application.ScreenUpdating = False FirstRow = Selection(1).Row FirstColumn = Selection(1).Column LastRow = FirstRow + Selection.Rows.Count - 1 LastColumn = FirstColumn + Selection.Columns.Count - 1 RowCount = Selection.Rows.Count ColumnCount = Selection.Columns.Count If RowCount < ColumnCount Then MsgBox ("You have not selected an equal number of rows as columns. Please go back and make sure they are the same and re-run.") Exit Sub Else If RowCount = 1 Or ColumnCount = 1 Then MsgBox ("You have either select just one row, one column or one cell please select a square range and re-run") Exit Sub End If End If RangeSelection = Range(Cells(FirstRow, FirstColumn), Cells(LastRow, FirstColumn)).Address(False, False) For x = 1 To RowCount - 1 RangeSelection = RangeSelection & "," & Range(Cells(FirstRow, FirstColumn + x), Cells(LastRow - x, FirstColumn + x)).Address(False, False) Next x Range(RangeSelection).Select End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Problem with named range for a large spreadsheet in Excel 2007 | Excel Discussion (Misc queries) | |||
Large formula problem | Excel Programming | |||
Big problem with large spreadsheet. | Excel Discussion (Misc queries) | |||
Solver - problem too large | Excel Worksheet Functions | |||
How to search a range for a suburb in a large range | Excel Programming |