LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default Evaluate v. WorksheetFunction: best practice?

"Bob Phillips" wrote
in m.p.e.worksheet.functions (" SumProduct not Working in a Macro"):
"Joe User" <joeu2004 wrote [...]:
try:
Range("I10") = Evaluate("SumProduct(--(H2:H10 = H10))")

or for that functionality, more simply:
Range("I10") = Evaluate("countif(H2:H10,H10)")


If you are going to use COUNTIF there is no need for
evaluate, that is only necessary for array formulae.


I presume Bob is suggesting using WorksheetFunction.CountIf(Range("h2:h10"),
Range("h10")) instead.

But WorksheetFunction.CountIf does not execute exactly the same code that
Evaluate("countif(...)") does. For example, WorksheetFunction.CountIf
returns zero when the range is composed of strings that are all longer than
255, whereas Evaluate("countif(...)") returns an error, just as the Excel
function COUNTIF does. In that case, I would prefer the error, rather than
having to troubleshoot an inexplicable result of zero.

This is especially relevant in the context because the OP noted later that
his/her reason for choosing SUBPRODUCT instead of COUNTIF is because the
latter fails if cells contain more than 255 characters(!), a situation that
was common in his/her context.

I have encountered another example, in recent months, where the two
approaches return different results under certain circumstances.
Unfortunately, I cannot remember the other function and how significant (or
not) the difference was; and I have not been able to find the thread where
this was discussed. (Can anyone else?)

I presume that Evaluate passes the string to Excel for evaluation, whereas I
believe that Worksheet.Function executes work-alike functions written for
VBA.

We pay a performance cost for this interprocess(?) communication. But for
this example, the difference is about 4 microsec on my computer. (YMMV.)

In most cases, I think I would be willing to pay the performance cost for
the peace of mind that the operation is performed exactly as it does in
Excel.

Comments?

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with WorksheetFunction.Index and WorksheetFunction.Match Luke Excel Programming 4 October 14th 09 12:57 AM
best practice? hsibbs Excel Discussion (Misc queries) 7 June 17th 05 04:11 AM
Evaluate or WorksheetFunction Problem SowBelly Excel Programming 2 August 28th 04 12:10 AM
WorkSheetFunction.CountIf & WorkSheetFunction.SumIf with 2 conditions? Etien[_2_] Excel Programming 3 January 13th 04 04:07 PM
Need Some Practice Linc Excel Programming 3 November 26th 03 01:36 PM


All times are GMT +1. The time now is 02:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"