Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with named range for a large spreadsheet in Excel 2007 Niranjan Excel Discussion (Misc queries) 0 January 26th 10 04:13 PM
Large formula problem Jim28 Excel Programming 10 June 25th 06 06:47 PM
Big problem with large spreadsheet. Rugby Al Excel Discussion (Misc queries) 1 August 18th 05 02:00 AM
Solver - problem too large Misssy Excel Worksheet Functions 1 August 10th 05 05:44 PM
How to search a range for a suburb in a large range Bogan.. Excel Programming 2 June 22nd 05 01:20 PM


All times are GMT +1. The time now is 03:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"