+ Reply to Thread
Results 1 to 12 of 12

Get Rows with highest value in a column

  1. #1
    Registered User
    Join Date
    01-08-2017
    Location
    London, Egnland
    MS-Off Ver
    Office 2016 mac
    Posts
    4

    Get Rows with highest value in a column

    Hi

    I have a spreadsheet with events data. I would like to get rows with the highest value of Business Criticality.

    If there are more than one rows with hightest values i would like to get all those rows and copy into a new sheet in same workbook. I would like to get header rows in the new sheet as well.

    Can some one please help with VBA for this?

    Pls see attached sample data sheet. For example i would like to copy the three highlighted rows to a new sheet [As they are with highest business criticality 10 in the column]
    Attached Files Attached Files

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,945

    Re: Get Rows with highest value in a column

    Hi, welcome to the forum

    How do you define highest? What if you had 1x10, 1x11 and 1x9, what would you then pull out?
    Do you really need VBA for this? An INDEX/SMALL/IF() array formula would probably do this, you just put it on a new sheet and copy as needed
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    01-08-2017
    Location
    London, Egnland
    MS-Off Ver
    Office 2016 mac
    Posts
    4

    Re: Get Rows with highest value in a column

    If i had only three rows with criticality as 9, 10 and 11 then i would like pull out only one row with value 11 as that's the highest one.

    I need to do a few more opeartions so yes really need VBA. I am trying to get a few things with a click of a button so really need VBA.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,945

    Re: Get Rows with highest value in a column

    This is what I was refering to, once you set it up, no further action needed...
    A
    B
    C
    D
    1
    Event Name Column 2 Column 3 Column 4
    2
    EVT00003 Value Value Value
    3
    EVT00010 Value Value Value
    4
    EVT00017 Value Value Value

    A2=IFERROR(INDEX(Sheet1!A:A,SMALL(IF(Sheet1!$N$2:$N$20=MAX(Sheet1!$N$2:$N$20),ROW(Sheet1!$A$2:$A$20)),ROWS($A$1:A1))),"")
    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.
    Then copy down and across as needed.

    Provided you have the ranges set to cover your data, this will update automatically, dont even need to click anything

  5. #5
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,794

    Re: Get Rows with highest value in a column

    Just to show you how easy it is using formulae, I have set this up for you in the attached file using three formulae. In cell O2 of Sheet1 I have used this formula:

    =IF(N2=MAX(N:N),MAX(O$1:O1)+1,"-")

    which can be copied down to the bottom of your data or beyond to accommodate new data being added (I've copied to row 25 in the attached file, as can be seen with the hyphens). This formula identifies the records which match the criteria and allocates a unique sequential number to each one. I've put the following formula in cell O2 of Sheet2:

    =IFERROR(MATCH(ROWS($1:1),Sheet1!O:O,0),"-")

    which returns the row number of the first matching record, or "-" if there is no matching record. When copied down, this will look for the second, then the third matching record, and so on. You can then use this formula in cell A2:

    =IF(OR($O2="",$O2="-"),"",INDEX(Sheet1!A:A,$O2))

    which can be copied across to N2, and this will return the data from the appropriate columns of Sheet1 for the first matching record. The formulae in row 2 can then be copied down as far as you need them (I've copied to row 10) to accommodate the amount of data that you expect.

    This is now fully automatic - if you change one of those values of 10 in Sheet1 to 11, then the records displayed in Sheet2 will automatically adjust - no need to click a button.

    As Ford indicated, it is possible to do all this with one array formula in Sheet2, but I prefer this approach as it is quicker to execute and uses simpler formulae.

    Hope this helps.

    Pete
    Attached Files Attached Files

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,945

    Re: Get Rows with highest value in a column

    Nice example, Pete, perhaps I should have gone that route too

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,794

    Re: Get Rows with highest value in a column

    It takes a bit longer to describe, though !!

    Pete

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,945

    Re: Get Rows with highest value in a column

    Maybe, but not as long as explaining that array formula

  9. #9
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,794

    Re: Get Rows with highest value in a column

    Yes, I noticed that you didn't try to explain what it was doing - another reason for the OP to avoid it if it is hard to understand the different elements.

    Thanks for the rep, by the way.

    Pete

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,945

    Re: Get Rows with highest value in a column

    You make a good point - and you are welcome

  11. #11
    Registered User
    Join Date
    01-08-2017
    Location
    London, Egnland
    MS-Off Ver
    Office 2016 mac
    Posts
    4

    Re: Get Rows with highest value in a column

    Really appreciate your help guys.
    Don't get me wrong, I have to do this using VBA. I know but that's the requirement I am working with.

    Any chance of doing this using VBA please?

  12. #12
    Registered User
    Join Date
    01-08-2017
    Location
    London, Egnland
    MS-Off Ver
    Office 2016 mac
    Posts
    4

    Re: Get Rows with highest value in a column

    Any help here please ?

+ 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. Replies: 3
    Last Post: 06-09-2016, 12:51 PM
  2. [SOLVED] Need to select earliest five rows matching highest value, and next highest if not enough
    By Ochimus in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-05-2016, 11:26 AM
  3. highlight duplicate rows and delete based on highest value from column
    By adnan5586 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-10-2015, 02:05 AM
  4. Macro to select rows with respect to highest value in column
    By gokzee in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-05-2012, 09:41 PM
  5. Picking the highest value from a column and then the next highest
    By johnb28 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-23-2008, 01:20 PM
  6. Replies: 4
    Last Post: 01-17-2008, 06:05 PM
  7. Replies: 3
    Last Post: 08-10-2006, 11:40 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