View Single Post
  #15   Report Post  
Posted to microsoft.public.excel.programming
Tim Zych[_8_] Tim Zych[_8_] is offline
external usenet poster
 
Posts: 18
Default When do you need .Value?

I ran a quick test and found that omitting the .Value ran *slightly* faster.
Kind of surprising. I expected the .Value version to be faster.

This took approximately .75 seconds on average to run.
Sub TestNoValue()
Dim i As Integer
Dim cell As Range
For i = 1 To 10000
Set cell = Cells(i, 1)
cell = i
cell(, 2) = cell
Next i
End Sub

while this took approximately .781 seconds on average to run.
Sub TestValue()
Dim i As Integer
Dim cell As Range
For i = 1 To 10000
Set cell = Cells(i, 1)
cell.Value = i
cell(, 2).Value = cell.Value
Next i
End Sub


"SunTzuComm" wrote in message
...
Dick,

I didn't expect to trigger a discussion of semantics. I was thinking of

OOP in
general: Anything that has a property is an object, even if that thing is
itself a property of another object. If the Cells property returns a

Range
object whose default property is Value, then Cells is as good as an object
whose default property is also Value. If that's not the terminology

Excel's
object model uses, I apologize profusely.

Omitting the default property MAY be more efficient because parsing is
processing intensive, and a look-up is, well, just a look-up. I have no

hard
evidence for this, and I'm not going to spend time testing the theory, but

it
seems that whenever one can omit source code from an Excel macro, one MAY

be
reducing run time. I, too, always include each default property, if only

for
the sake of documentation.

Regards,
Wes