+ Reply to Thread
Results 1 to 16 of 16

A More Efficient Method Than the Evaluate Method?

  1. #1
    Registered User
    Join Date
    02-06-2010
    Location
    Syracuse, NY
    MS-Off Ver
    Excel 2007
    Posts
    23

    A More Efficient Method Than the Evaluate Method?

    I'm looking to gain efficiency in some script I've written. I use the inefficient "Evaluate" method to return the minimum and maximum values in a range that meet a certain criteria:

    Please Login or Register  to view this content.
    The variable dblCohort is the criteria by which the function defines the conditional value to return. Basically, I'm looking for a function in VBA that returns the minimum and maximum values in a range that uses conditional arguments much in the same way SUMIFS, AVERAGEIFS or COUNTIFS do.

    I suspect there's an easy solution, but I either don't know the solution or I'm blanking on it. I've searched through this forum and the on the internet with no luck. Any suggestions?

    Tony

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: A More Efficient Method Than the Evaluate Method?

    There isn't one. Why do you think Evaluate is so inefficient?
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    02-06-2010
    Location
    Syracuse, NY
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: A More Efficient Method Than the Evaluate Method?

    Quote Originally Posted by romperstomper View Post
    There isn't one. Why do you think Evaluate is so inefficient?
    Hey romperstomper.

    Maybe "inefficient" is the wrong term. But when I comment those two lines out, my tool runs 44% faster. The code uses SUMIFS and COUNTIFS quite a bit, which means that these two functions don't seem to have the same effect operating on the same range that the Evaluate method does.

    And since the tool I built loops through at least 12 different workbooks, 44% is quite a considerable difference in time.

    Do you think there's a better way to go about this?

    Tony

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: A More Efficient Method Than the Evaluate Method?

    Start by restricting the range you operate on, and also use the Evaluate method of the parent worksheet - supposed to be faster (though that may be moot if it's the active sheet)

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: A More Efficient Method Than the Evaluate Method?

    Perhaps efficiency would increase if you adjusted your Evaluate formulas to only the range of data instead of the entire column?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  6. #6
    Registered User
    Join Date
    02-06-2010
    Location
    Syracuse, NY
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: A More Efficient Method Than the Evaluate Method?

    Quote Originally Posted by romperstomper View Post
    Start by restricting the range you operate on, and also use the Evaluate method of the parent worksheet - supposed to be faster (though that may be moot if it's the active sheet)
    Thanks for the suggestion. Since the tool loops through many workbooks,the ranges the Evaluate method operates on are of different dimensions -- one range may have 24 rows, another may have 2400. No matter,though: it's easy enough to create variables that capture each range's dimension.

    And if I'm understanding your second statement correctly, since I'm setting and activating the worksheet (I need to do this because I'm applying a filter to it), I believe I'm using the Evaluate method of the parent worksheet. Though I can't be sure. Would you mind explaining the difference between the parent worksheet and any other type of worksheet?

    Tony

  7. #7
    Registered User
    Join Date
    02-06-2010
    Location
    Syracuse, NY
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: A More Efficient Method Than the Evaluate Method?

    Quote Originally Posted by JBeaucaire View Post
    Perhaps efficiency would increase if you adjusted your Evaluate formulas to only the range of data instead of the entire column?
    Thanks for the suggestion JBeaucaire. I agree with you and romperstomper, restricting the ranges will increase efficiency, even if only marginally. (Every bit helps.)

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: A More Efficient Method Than the Evaluate Method?

    I'm setting and activating the worksheet (I need to do this because I'm applying a filter to it), I believe I'm using the Evaluate method of the parent worksheet.
    That's true, though I don't see why you need to select a sheet to filter it.
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Registered User
    Join Date
    02-06-2010
    Location
    Syracuse, NY
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: A More Efficient Method Than the Evaluate Method?

    Quote Originally Posted by shg View Post
    That's true, though I don't see why you need to select a sheet to filter it.
    Sorry, I meant sorting, not filtering. I need to activate the worksheet to apply a sort to the table.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: A More Efficient Method Than the Evaluate Method?

    You don't need to select the sheet to sort, either.

  11. #11
    Registered User
    Join Date
    02-06-2010
    Location
    Syracuse, NY
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: A More Efficient Method Than the Evaluate Method?

    Quote Originally Posted by shg View Post
    You don't need to select the sheet to sort, either.
    Thanks for the input shg. I must be doing something wrong because when I comment out .Activate, I get this error:

    Run-time error '1004':

    The sort reference is not valid. Make sure that it's written within the data you want to sort, and the first Sort By box isn't the same or blank.
    It breaks at the last line shown here:

    Please Login or Register  to view this content.
    Am I coding it incorrectly?

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: A More Efficient Method Than the Evaluate Method?

    Unqualified, a range reference is to the active worksheet, so ...
    Please Login or Register  to view this content.
    Last edited by shg; 12-21-2011 at 03:41 PM.

  13. #13
    Registered User
    Join Date
    02-06-2010
    Location
    Syracuse, NY
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: A More Efficient Method Than the Evaluate Method?

    Quote Originally Posted by shg View Post
    Unqualified, a range reference is to the active worksheet, so ...
    Please Login or Register  to view this content.
    Thanks. I clearly missed that little bit.

    I'll update shortly on the progress.

  14. #14
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: A More Efficient Method Than the Evaluate Method?

    You're welcome.

    No need to quote whole posts, please, it just clutters the forum.

  15. #15
    Registered User
    Join Date
    02-06-2010
    Location
    Syracuse, NY
    MS-Off Ver
    Excel 2007
    Posts
    23

    [SOLVED] A More Efficient Way to Employ the Evaluate Method

    Efficiency gained! Thanks to the help on everyone who chimed in today, the tool runs 4.25 faster.

    Thanks again.

  16. #16
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: A More Efficient Method Than the Evaluate Method?

    4.25 what? Times, seconds, minutes, days?

    FWIW, I was referring to the difference between Application.Evaluate and Worksheet.Evaluate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1