E
ExcelMonkey
This is further to string between Tim Zych and I from December
http://www.microsoft.com/office/com...5298&catlist=&dglist=&ptlist=&exp=&sloc=en-us
The Sub below loades cell addresses into a range object and pulls the
contiguous addresses together via a Union function. Now I am trying to load
a large number of cell addresses from an array into the range object. The
array is large and breaches the limit on the # of characters that I can put
into the Range Object in VBA. For example if I try to load the example below
the sub into the range object, I will get an error message. Note only the
first address Sheet1!A1 and the last cell address Sheet1!A2 are contigous
QUESTION:
Is it possible to keep creating additional range objects as needed to avoid
the error? And if I am going to have to split these up between multiple
range objects, I want to ensure that all contiguous cells are in the same
range object and then fed into the Union Function. In the example provided,
if multiple range objects are created, then the last cell address (Sheet1!A2)
will not be joined with the first cell address (Sheet1!A1) via the union
function. I am assuming I would need a routine which checks all th range
objects prior to the union function being applied to each range object.
Or is there a better way to do this relative to the multiple range object
approach?
'******************************
Sub CountAreas()
Dim rng As Range
Dim rngArea As Range
Dim rngUnion As Range
Set rng = Range("Sheet1!A1,Sheet1!A2,Sheet1!A3,Sheet1!A4")
Set rngUnion = rng.Areas(1)
For Each rngArea In rng.Areas
Set rngUnion = Union(rngUnion, rngArea)
Next
For Each rngArea In rngUnion.Areas
Debug.Print rngArea.Address(0, 0, , True)
Debug.Print rngArea.Parent.Name & "!" & rngArea.Address(0, 0)
Next
End Sub
'**********************************88
Range("Sheet1!A1,Sheet1!A3,Sheet1!A5,Sheet1!A7,Sheet1!A9,Sheet1!A11,Sheet1!A13,Sheet1!A15,Sheet1! _
Sheet1!A17,Sheet1!A19,Sheet1!A21,Sheet1!C1,Sheet1!C3,Sheet1!C5,Sheet1!C7,Sheet1!C9,Sheet1!C11, _
Sheet1!C13,Sheet1!C15,
Sheet1!C17,Sheet1!C19,Sheet1!C21,Sheet1!E1,Sheet1!E3,Sheet1, Sheet1!E5, _
Sheet1!E7,Sheet1!E9,Sheet1!E11,Sheet1!E13,Sheet1!E15,Sheet1!E17,Sheet1!E19,Sheet1!E21,Sheet1!G1, _
Sheet1!G3,Sheet1!G5,Sheet1!G7,Sheet1!G9,Sheet1!G11,Sheet1!G13,
Sheet1!G15,Sheet1!G17,Sheet1!G19, _
Sheet1!G21,Sheet1!I1,Sheet1!I3,Sheet1!I5,Sheet1!I7,Sheet1!I9,Sheet1!I11,Sheet1!I13,Sheet1!I15,Sheet1!I17, _
Sheet1!I19,Sheet1!I21,Sheet1!K1,Sheet1!K3,Sheet1!K5,Sheet1!K7,Sheet1!K9,Sheet1!K11,Sheet1!K13, _
Sheet1!K15,Sheet1!K17,Sheet1!K19,Sheet1!K21,Sheet1!M1,Sheet1!M3,Sheet1!M5,Sheet1!M7,Sheet1!M9, _
Sheet1!M11,Sheet1!M13,Sheet1!M15,Sheet1!M17,Sheet1!M19,Sheet1!M21,Sheet1!A2")
Thanks
EM
http://www.microsoft.com/office/com...5298&catlist=&dglist=&ptlist=&exp=&sloc=en-us
The Sub below loades cell addresses into a range object and pulls the
contiguous addresses together via a Union function. Now I am trying to load
a large number of cell addresses from an array into the range object. The
array is large and breaches the limit on the # of characters that I can put
into the Range Object in VBA. For example if I try to load the example below
the sub into the range object, I will get an error message. Note only the
first address Sheet1!A1 and the last cell address Sheet1!A2 are contigous
QUESTION:
Is it possible to keep creating additional range objects as needed to avoid
the error? And if I am going to have to split these up between multiple
range objects, I want to ensure that all contiguous cells are in the same
range object and then fed into the Union Function. In the example provided,
if multiple range objects are created, then the last cell address (Sheet1!A2)
will not be joined with the first cell address (Sheet1!A1) via the union
function. I am assuming I would need a routine which checks all th range
objects prior to the union function being applied to each range object.
Or is there a better way to do this relative to the multiple range object
approach?
'******************************
Sub CountAreas()
Dim rng As Range
Dim rngArea As Range
Dim rngUnion As Range
Set rng = Range("Sheet1!A1,Sheet1!A2,Sheet1!A3,Sheet1!A4")
Set rngUnion = rng.Areas(1)
For Each rngArea In rng.Areas
Set rngUnion = Union(rngUnion, rngArea)
Next
For Each rngArea In rngUnion.Areas
Debug.Print rngArea.Address(0, 0, , True)
Debug.Print rngArea.Parent.Name & "!" & rngArea.Address(0, 0)
Next
End Sub
'**********************************88
Range("Sheet1!A1,Sheet1!A3,Sheet1!A5,Sheet1!A7,Sheet1!A9,Sheet1!A11,Sheet1!A13,Sheet1!A15,Sheet1! _
Sheet1!A17,Sheet1!A19,Sheet1!A21,Sheet1!C1,Sheet1!C3,Sheet1!C5,Sheet1!C7,Sheet1!C9,Sheet1!C11, _
Sheet1!C13,Sheet1!C15,
Sheet1!C17,Sheet1!C19,Sheet1!C21,Sheet1!E1,Sheet1!E3,Sheet1, Sheet1!E5, _
Sheet1!E7,Sheet1!E9,Sheet1!E11,Sheet1!E13,Sheet1!E15,Sheet1!E17,Sheet1!E19,Sheet1!E21,Sheet1!G1, _
Sheet1!G3,Sheet1!G5,Sheet1!G7,Sheet1!G9,Sheet1!G11,Sheet1!G13,
Sheet1!G15,Sheet1!G17,Sheet1!G19, _
Sheet1!G21,Sheet1!I1,Sheet1!I3,Sheet1!I5,Sheet1!I7,Sheet1!I9,Sheet1!I11,Sheet1!I13,Sheet1!I15,Sheet1!I17, _
Sheet1!I19,Sheet1!I21,Sheet1!K1,Sheet1!K3,Sheet1!K5,Sheet1!K7,Sheet1!K9,Sheet1!K11,Sheet1!K13, _
Sheet1!K15,Sheet1!K17,Sheet1!K19,Sheet1!K21,Sheet1!M1,Sheet1!M3,Sheet1!M5,Sheet1!M7,Sheet1!M9, _
Sheet1!M11,Sheet1!M13,Sheet1!M15,Sheet1!M17,Sheet1!M19,Sheet1!M21,Sheet1!A2")
Thanks
EM