PDA

View Full Version : Solved: What are the differences between two?



YellowLabPro
03-14-2007, 08:42 PM
I found these two examples in the help section: what are the differences? I do not understand what Evaluate is doing. The definition is-
"Converts a Microsoft Excel name to an object or a value"

Sub test2()
Worksheets("sheet1").Activate
boldCell = "A1:C5"
Evaluate(boldCell).Font.Bold = True
End Sub

Sub Test3()
Worksheets("Sheet1").Range("A1:C5").Font.Bold = True
End Sub

Thanks,

YLP

Bob Phillips
03-14-2007, 08:46 PM
There is no difference between the end result in the two examples.

The Evaluate method takes a string argument and returns the object or value that the string refers to. It is also pretty inefficient and should be avoided unless there is no other option, which is not the case here.

YellowLabPro
03-14-2007, 08:52 PM
Hi Xld,
What makes it inefficient?

Bob Phillips
03-14-2007, 08:55 PM
The amount of work that has to gon, the string has to be parsed, checked for validity, and then evaluated. Referencing the object directly avoids all of this.

YellowLabPro
03-14-2007, 09:09 PM
Ok....

Thanks