+ Reply to Thread
Results 1 to 22 of 22

Mode function to show min. value when it's a tie

  1. #1
    Registered User
    Join Date
    10-30-2017
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    30

    Mode function to show min. value when it's a tie

    Hi,
    I want VBA-code below to show lowest "mode-value" in a range.
    I use "On error Resume next" for ranges with only single values.
    rng4 is a vertical one column range

    Please Login or Register  to view this content.
    ie. If rng4 have numbers like: 1,2,2,3,3,5,5,6,7, I want MODE to show: 2
    Is that possible?

    Any help will be much appreciated.
    Thanks in advance!

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Mode function to show min. value when it's a tie

    In case values are
    1,2,3,2,3,3,5,5,6,7,

    What's the result you expect ?
    - Battle without fear gives no glory - Just try

  3. #3
    Registered User
    Join Date
    10-30-2017
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Mode function to show min. value when it's a tie

    Hi,
    Thanks for answer.

    That's not a problem for Mode. Answer is 3.

  4. #4
    Registered User
    Join Date
    10-30-2017
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Mode function to show min. value when it's a tie

    For clairification.
    If values are:
    8,8,9,9,9,10,10,10,11
    I want result to be 9.

  5. #5
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Mode function to show min. value when it's a tie

    What is the issue with your code it looks nice ??

  6. #6
    Registered User
    Join Date
    10-30-2017
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Mode function to show min. value when it's a tie

    I have about 95 columns to check.
    One column have values: 3,2,2,7,9,5,3,1,7,5
    There are four ties! 2x2, 2x3, 2x5 and 2x7
    My code results in: 7
    I want it to show: 2
    2 is the lowest value of 2,3,5 and 7

  7. #7
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Mode function to show min. value when it's a tie

    Can you attach an Excel sample file, it will help to debug

  8. #8
    Registered User
    Join Date
    10-30-2017
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Mode function to show min. value when it's a tie

    Ok, but now I have to go. I will try to answer in about six hours or tomorrow.
    Thanks a lot for your time.

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

    Re: Mode function to show min. value when it's a tie

    Try
    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Mode function to show min. value when it's a tie

    See next function
    Please Login or Register  to view this content.
    But have you had a look on the use of a Pivot Table it may help

  11. #11
    Registered User
    Join Date
    10-30-2017
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Mode function to show min. value when it's a tie

    Thanks for your answers jindon and PCI

    jindon
    That line did the trick.
    After implementing this line in my code, I encountered another problem.
    I'm almost there but I can't figure it out how to solve it.

    Range can be empty or up to hundreds of populated cells (no empty cells between numbers).
    Range is now set up to be the eight last cells in each column.
    I want Target10 to show the smallest, most frequently occurring number in the range.
    If all numbers are single numbers, I want Target10 to show smallest number in range.

    Example:
    Range ("A32") = 8
    Range("B14:B21"), numbers = 1,2,3,4,5,5,7,8
    Target10 shows "1".
    It should show "5".
    Here is code:

    Please Login or Register  to view this content.
    Any idea how to fix that?
    Thanks in advance!

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

    Re: Mode function to show min. value when it's a tie

    If I understand,
    Try change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Last edited by jindon; 04-23-2019 at 02:53 AM.

  13. #13
    Registered User
    Join Date
    10-30-2017
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Mode function to show min. value when it's a tie

    jindon,
    So strange! I didn't get any notification in my e-mail for your last reply.
    I just noticed it now when I wanted to show my own solution and close the post.
    I think I tried your last answer earlier but it was problems with columns with less numbers than cells with or without duplicates, in range area.
    Anyway, after twelve hours of coding and endless tests, I came up with this solution:

    Please Login or Register  to view this content.
    If you can see any flaws in code I would be very grateful if you pointed it out.
    All credit to you and your first answer that guided me in the right direction.

    Thanks a lot.
    Last edited by soidog; 04-24-2019 at 05:03 AM.

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

    Re: Mode function to show min. value when it's a tie

    WorksheetFunction.Min(WorksheetFunction.Mode_Mult(rng3)) should work as just Min if there is no duplicate, so
    Please Login or Register  to view this content.
    would be
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    10-30-2017
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Mode function to show min. value when it's a tie

    That gave me:

    Run-time error '1004':
    Unable to get Mode_Mult property of the WorksheetFunction class

    in first column without duplicate.
    Column have numbers: 8,9,10,11,12,13,14,15,16 starting in row 14. Number 9 - 16 selected.

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

    Re: Mode function to show min. value when it's a tie

    Ahhh, OK
    How about
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    10-30-2017
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Mode function to show min. value when it's a tie

    Same error at same column.
    Line highlighted:
    Target10.Value = WorksheetFunction.Min(WorksheetFunction.Mode_Mult(rng4))

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

    Re: Mode function to show min. value when it's a tie

    That's impossible.
    It should ignore the error.

    Did you copy from the top,"On Error Resume Next"?

  19. #19
    Registered User
    Join Date
    10-30-2017
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Mode function to show min. value when it's a tie

    That's exactly what I did NOT do.
    Works like a charm!!!

    Considering this piece of code is just a part in a larger code, I wonder if "On Error Resume Next" can cause problems?

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

    Re: Mode function to show min. value when it's a tie

    OK then
    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    10-30-2017
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Mode function to show min. value when it's a tie

    Thanks a lot jindon.
    You are the best.

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

    Re: Mode function to show min. value when it's a tie

    You are welcome and thanks for the rep.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

+ 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. PowerPoint to automatically update while in slide show mode
    By angel2903 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-31-2015, 12:43 PM
  2. show in cell errors in protected mode
    By trevor69 in forum Excel General
    Replies: 2
    Last Post: 01-11-2015, 03:28 PM
  3. Option buttons show error in protected mode
    By jghender in forum Excel General
    Replies: 1
    Last Post: 12-28-2012, 10:19 PM
  4. Show value of variable on mouse-over in debug mode - bug?
    By Chet Shannon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-09-2006, 04:55 PM
  5. How show value of variable by mouse-over in debug single step mode
    By Chet Shannon in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-06-2006, 11:35 AM
  6. [SOLVED] How show value of variable in single step debug mode?
    By Chet Shannon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-28-2005, 03:00 AM
  7. form.show switches to debug mode
    By rooch84 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-05-2005, 09:05 PM

Tags for this Thread

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