+ Reply to Thread
Results 1 to 24 of 24

Return 10 largest values using VBA

  1. #1
    Registered User
    Join Date
    01-30-2013
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    24

    Return 10 largest values using VBA

    Hi

    I have this sheet where i want to return the 10 largest values in a msgbox.

    e.g. i have

    A B
    Martin 10
    Brian 10
    Kitt 9
    Jens 11
    Peter 1

    and many more. Then i want a msgbox showing me the 10 largest values and the name. Ive tried this code:

    Please Login or Register  to view this content.
    But when im running the code i get a msgbox with e.g

    Jens 11
    Martin 10
    Martin 10 -should have been Brian!
    Kitt 9

    etc.

    Please help =) Thank you!

    Best Regards Martin
    Attached Files Attached Files
    Last edited by Martinbif; 06-29-2013 at 02:35 AM. Reason: Code tags added

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

    Re: Return 10 largest values using VBA

    Why not just sort by score?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Return 10 largest values using VBA

    Isn't Sorting the range quickest?

    Anyway..
    Please Login or Register  to view this content.

  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
    53,048

    Re: Return 10 largest values using VBA

    Martinbif Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    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

  5. #5
    Registered User
    Join Date
    01-30-2013
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Return 10 largest values using VBA

    Hi Jindon

    Thanks for your answer. I am quite new to VBA programming. When i use your code i get this outputCapture.JPG.

    I want to illustrate in my msgbox the name of the team and how many wins top 10 has =) Afterwards i want top 10 away wins, etc. Could you please help me understand your code? Thanks! =)

    Best Regards
    Martin

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Return 10 largest values using VBA

    You have nothing in col.A.

    Upload your file rather then uploading picture.

  7. #7
    Registered User
    Join Date
    01-30-2013
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Return 10 largest values using VBA

    Hi Jindon

    The file is uploaded now =) Im working in the sheet "overblik" atm =)

    Thanks

    / Martin

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Return 10 largest values using VBA

    Change to
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    01-30-2013
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Return 10 largest values using VBA

    Hi jindon!

    Thanks alot. Works almost perfect. Only issue is that i get som random numbers: Capture.JPG

    Also could you help me understand the code? Im very new to VBA and would like to understand wich code does what to be able to modify later =)

    Thanks alot!

    / Martin

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Return 10 largest values using VBA

    What and where is RANDOM NUMBERS?

  11. #11
    Registered User
    Join Date
    01-30-2013
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Return 10 largest values using VBA

    To the left in my msgbox =)

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Return 10 largest values using VBA

    They are RANK.

    Do you want to have top 10 from the Total wins?
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    01-30-2013
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Return 10 largest values using VBA

    Arh perfect... i understand now... it is because it dont fill the rank in the msgbox when they are the same =)

    thanks alot!

  14. #14
    Registered User
    Join Date
    01-30-2013
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Return 10 largest values using VBA

    Hi Jindon =)

    A quick question.. How do i modify the msgbox to only show one decimal when returning %? e.g. 31,1 % instead of 0,311234383493 ?

    Thanks in advance =)

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Return 10 largest values using VBA

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    01-30-2013
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Return 10 largest values using VBA

    Thanks =)

    How to make it general? work on all values if more than one? I mean how to make 0.311.... general for the whole msgbox? =)

    Thanks

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Return 10 largest values using VBA

    I don't understand what you are asking and how is it related to your original question?

    The forum allows only one question per thread.

  18. #18
    Registered User
    Join Date
    01-30-2013
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Return 10 largest values using VBA

    It is related because it is related to the output of my original question?

    What you showed my was to make one value into %... As you saw in my sheet i got many values.. So im asking how to make the msgbox so it applys to all instead of a single value =)

    But nwm if i had to make a new thread then i must do that apperently

    / Martin

  19. #19
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Return 10 largest values using VBA

    As I said, I don't understand what you are asking.

  20. #20
    Registered User
    Join Date
    01-30-2013
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Return 10 largest values using VBA

    Recall the msgbox from earlier Capture.JPG

    Imagine that there are decimals instead of integers... Then im asking how to make them all into % instead of e.g. 0,453232121 and not only one number from earlier 0,31.... =)

  21. #21
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Return 10 largest values using VBA

    So, how is it related to RANK?

    Your question is really vague.

    Show me the example with your desired result in a workbook.

  22. #22
    Registered User
    Join Date
    01-30-2013
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Return 10 largest values using VBA

    Capture.JPG

    As you can se on the picture all the values are in decimals, i want them to be in % =)

  23. #23
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Return 10 largest values using VBA

    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    01-30-2013
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Return 10 largest values using VBA

    Thank you very much =)

+ 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