+ Reply to Thread
Results 1 to 9 of 9

Finding 5 largest values in a column and then returning the rows that correspond

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

    Finding 5 largest values in a column and then returning the rows that correspond

    Hi,

    I have a macro where i need to identify the 5 largest values in a specific column of data. Note: Lets say there are 30 columns of data in this file.
    I need to copy and paste the rows which correspond to these 5 largest values into another worksheet. I am not sure the best way to do this. I was thinking of using "FIlters" but i am not sure how yet.

    Any thoughts on how to approach this?

  2. #2
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Finding 5 largest values in a column and then returning the rows that correspond

    this will give you the row numbers you will need to use to copy the rows

    Please Login or Register  to view this content.
    this will give you an idea how to approach things
    Attached Files Attached Files
    Last edited by nigelog; 01-22-2020 at 01:30 PM.

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

    Re: Finding 5 largest values in a column and then returning the rows that correspond

    that code works!!!!!!!! but i am not sure why it works. can you explain it just a little.

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

    Re: Finding 5 largest values in a column and then returning the rows that correspond

    ok, i think i understand now...i had to look up the worksheet function "Large" to see how it worked. I had never heard of this worksheet function before.

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

    Re: Finding 5 largest values in a column and then returning the rows that correspond

    one more question....i see how the "filter" and "Large" things work....and i am playing with them still just to see if there are any issues.

    But i did have a similar question about if this type of thing could be done with values that are stored in a dictionary.

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: Finding 5 largest values in a column and then returning the rows that correspond

    You could also use an autofilter for values >= the 5th largest value.
    Rory

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

    Re: Finding 5 largest values in a column and then returning the rows that correspond

    Any idea on how to do this is you could not use the worksheetfunction.large. For example, if you had an array of values how you would determine the top 5 values? And their corresponding row numbers?

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

    Re: Finding 5 largest values in a column and then returning the rows that correspond

    So if we use the "Large" method...we need to know the range. But what is the range when we already have filters on for say country....see enclosed file.

    We need to know top 5 days and their corresponding rows...........for say country USA.......how to use this then.
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this ‼

    Quote Originally Posted by welchs101 View Post
    For example, if you had an array of values how you would determine the top 5 values? And their corresponding row numbers?
    Quote Originally Posted by welchs101 View Post
    We need to know top 5 days and their corresponding rows...........for say country USA.......how to use this then.
    As always an easy way is the Excel basics, here LARGE & MATCH worksheet functions,
    even directly on a 'formula filtered' values array - so without the need of a worksheet filter - like according to your attachment
    this VBA demonstration where V is the Values array, T the Top five result array & R the top five Rows # :

    PHP Code: 
    Sub Demo1()
        
    Dim VTR
        With 
    [A1].CurrentRegion.Columns
            V 
    Evaluate("IF(" & .Item(1).Address "=""United States""," & .Item(2).Address ",-1)")
        
    End With
            T 
    Application.Large(V, [ROW(1:5)])
            
    Application.Match(TV0)
            
    Stop
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 01-24-2020 at 09:28 PM. Reason: simplification …

+ 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. Finding 3 largest values using LARGE function based on criteria in another column
    By cathyharland in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-23-2018, 02:17 AM
  2. [SOLVED] Finding values from one sheet that correspond to the right column/row of another sheet
    By hyperaura in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2013, 01:11 AM
  3. Replies: 1
    Last Post: 12-03-2012, 08:14 AM
  4. Replies: 4
    Last Post: 01-03-2012, 07:43 AM
  5. Replies: 1
    Last Post: 01-02-2012, 12:42 PM
  6. Replies: 0
    Last Post: 08-29-2005, 07:45 AM
  7. Finding Every Third Number and Returning the Largest of Them
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 08-25-2005, 02:56 AM

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