I got a difference of 1.18359375 seconds when I ran your code; but I have a
pretty fast computer here, so that time differential may not be
representative. In any case, point taken... limit the unionizing to groups
of 100 or so... even doing that should still produce an enormous improvement
over doing it in the straight forward, one-at-a-time iteration approach.
Thanks for pointing that out.
Rick
> One thing to watch out for with Union is that it becomes exponentially
> slower if/as the number of discontiguous areas in the unioned range
[quoted text clipped - 112 lines]
>>
> <snip>
Rick Rothstein (MVP - VB) - 16 Mar 2008 17:50 GMT
Ignore what I said about my timing... I misunderstood your posting and
thought your code measured the time-difference in a single run... I didn't
realize it was a two-step process requiring the bFastTest be flipped
manually for the two cases... the time I reported was the time it took to
run the "chunk" method. I had to break into the "non-chunk" method as it was
taking too long. Again, thanks for pointing this problem out. By the way,
for those out there following this thread, the reason all this is important
is the Union technique has application to deleting rows of data (a
relatively common question in these groups) and the apparently recommended
method is to iterate the data rows, from the last data row to the first,
deleting rows as you go... this Union technique (still requiring the
backward iterations if using Peter T's "chunk" method) promises to be an
enormously quicker approach, so it is important to fine-tune it as much as
is possible.
Rick
>I got a difference of 1.18359375 seconds when I ran your code; but I have a
>pretty fast computer here, so that time differential may not be
[quoted text clipped - 122 lines]
>>>
>> <snip>
Peter T - 16 Mar 2008 18:27 GMT
"Rick Rothstein (MVP - VB)" wrote in message
> Ignore what I said about my timing... I misunderstood your posting and
> thought your code measured the time-difference in a single run... I didn't
> realize it was a two-step process requiring the bFastTest be flipped
> manually for the two cases... the time I reported was the time it took to
> run the "chunk" method. I had to break into the "non-chunk" method as it was
> taking too long.
Yes I can see now it was not clear how to test. Although normally in such a
test routine it would compare first one way then the other, but in this case
for most systems it would not be possible to do the second test which would
involve making a union of 20k areas. Hence the comment in the routine to
reduce the range before testing the 'big' union method.
Regards,
Peter T
PS more posts crossing - in future I will wait at least 5 minutes before
responding <g>
Peter T - 16 Mar 2008 18:03 GMT
Was that making a union of 2k areas (loop of 4000 cells) or 20k areas (40k
cells). If the if the latter I can only assume your machine runs on a
combination of nitrous-oxide and steroids. For my curiosity how long for you
to run this -
Sub SteroidTest()
Dim i As Long
Dim t As Single
Dim rng As Range
t = Timer
For i = 1 To 40000 Step 2
If rng Is Nothing Then
Set rng = Cells(i, 1)
Else
Set rng = Union(rng, Cells(i, 1))
End If
Next
Debug.Print Timer - t ' ?
Debug.Print rng.Areas.Count ' 20,000
End Sub
Regards,
Peter T
> I got a difference of 1.18359375 seconds when I ran your code; but I have a
> pretty fast computer here, so that time differential may not be
[quoted text clipped - 121 lines]
> >>
> > <snip>
Peter T - 16 Mar 2008 18:19 GMT
My turn to say ignore that - our posts crossed.
Regards,
Peter T
"Peter T" <peter_t@discussions> wrote in message
> Was that making a union of 2k areas (loop of 4000 cells) or 20k areas (40k
> cells). If the if the latter I can only assume your machine runs on a
> combination of nitrous-oxide and steroids. For my curiosity how long for you
> to run this -
<snip>
Rick Rothstein (MVP - VB) - 16 Mar 2008 18:22 GMT
I see you haven't read my follow up post to the one you just responded to
yet...
Rick
> Was that making a union of 2k areas (loop of 4000 cells) or 20k areas (40k
> cells). If the if the latter I can only assume your machine runs on a
[quoted text clipped - 158 lines]
>> >>
>> > <snip>