+ Reply to Thread
Results 1 to 7 of 7

More efficient way to find max value for an array of values

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    More efficient way to find max value for an array of values

    Hi,

    I have a macro that works.........but it takes ~23sec to run. I am trying to find a quicker more efficient way to do the same thing. I am thinking a scripting dictionary way might be the answer.

    What macro is supposed to do:
    See "Data_And_Output" worksheet. Three cols of data on this sheet.

    SubjectIDs: List of subject values
    Expected: Expected value for each subject
    Max Expected: This is the column the macro calculates. Maximum expected value for subject value listed in col-A.

    NOTE: In order to attach file i had to reduce the number of rows.......originally number of rows was 108770. BUt i am reducing it to 70,000 rows
    Attached Files Attached Files

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,984

    Re: More efficient way to find max value for an array of values

    Try this:
    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: More efficient way to find max value for an array of values

    thanks romperstomper............

    do you also know a scripting dictionary approach.

    i am trying to learn how to use the scipting dic and trying to apply it to many of the scenarios i run into.

    thanks.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,984

    Re: More efficient way to find max value for an array of values

    Seems unnecessary here, but:
    Please Login or Register  to view this content.
    would be one way.

  5. #5
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: More efficient way to find max value for an array of values

    as an option
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: More efficient way to find max value for an array of values

    first method using R1C1 formula takes ~ 2sec
    scripting method takes ~0.6sec
    nilems sort/arrays ~ 0.2sec


    i am surprised that the scripting method is slower than the sort/array method...........

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: More efficient way to find max value for an array of values

    In the first code, there is no loop. No matter how scripting could be fast, it can not be faster than non looping code, for e.g. filter. You can only compare scripting with looping though a range.
    Last edited by AB33; 09-02-2013 at 01:43 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Find a value in an array and return multiple values in an adjacent array
    By tonbra in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2012, 08:35 PM
  2. Find the top 3 values of an array
    By alphecca in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-21-2011, 02:56 PM
  3. Most efficient way to find string in array members
    By davegugg in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-06-2010, 12:08 PM
  4. Replies: 13
    Last Post: 01-26-2010, 05:29 PM
  5. [SOLVED] Efficient Array Formula Construction
    By Mike Moore in forum Excel General
    Replies: 8
    Last Post: 07-23-2006, 07:37 PM

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