View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default without for loop

I agree, I think it doesn't even look pretty and never use it myself, but
that is what the OP used, and I was concentrating on the bit that he didn't
have.

As to the timings and 'simple' unions, it appears from the OP's previous
response that perhaps his unions will not be so simple :-)

I also added this version to your tests, which I expected to be fastest of
all, but it was approx 50% slower than your fastest

t = Timer
With Worksheets("Sheet1")
For i = 1 To m
Set u = .Range("a1:b2,d1:e2")
Next
End With
Debug.Print (Timer - t)

Bob

"keepITcool" wrote in message
ft.com...
Bob,

a while ago Tom Ogilvy advised me that using the
[] (or Evaluate) syntax for range refencing makes code
look pretty but execute slow.

Also I found that with 'simple' unions there's more to be
gained from syntaxing...

decreasing from 6 to .9 secs (for 100k calls)


Sub SyntaxSpeed()
Dim t!, i&, u As Range
Const m = 100000
t = Timer
For i = 1 To m
Set u = Union([sheet1!a1:b2], [sheet1!d1:e2])
Next
Debug.Print (Timer - t)

t = Timer
For i = 1 To m
Set u = Union(Range("sheet1!a1:b2"), Range("sheet1!d1:e2"))
Next
Debug.Print (Timer - t)

t = Timer
For i = 1 To m
Set u = Worksheets("sheet1").Range("a1:b2,d1:e2")
Next
Debug.Print (Timer - t)

t = Timer
For i = 1 To m
Set u = Range("sheet1!a1:b2,sheet1!d1:e2")
Next
Debug.Print (Timer - t)

End Sub





--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Bob Phillips wrote :

Don't know why loops are taboo, so here is one

Sub unii()
Dim sht As Worksheet
Set sht = ThisWorkbook.Sheets(1)
Dim uni As Range, uni_tar As Range
Dim area
Dim i As Long

Set uni = Union(sht.[A7:B7], sht.[A9:B9])
Set uni_tar = Union(sht.[A15:B15], sht.[A19:B19])
For i = 1 To uni_tar.Areas.Count
uni_tar.Areas(i).Value = uni.Areas(i).Value
Next i
End Sub