+ Reply to Thread
Results 1 to 11 of 11

VBA selecting top 3

  1. #1
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    VBA selecting top 3

    Dear Friends,

    I'm trying to make a macro that selects the 3 highest values and give these cells a blue backcolor. (The code should skip any blanc cells).


    Thanks you for any help offered.

    Greetings,

    Roberto, The Netherlands
    Last edited by roberto1111; 10-30-2009 at 01:17 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA selecting top 3

    No macro needed. Use conditional formatting.

    1) Remove all the background coloring.
    2) Highlight B1:N1
    3) Use this conditional format:
    Condition1: Formula Is: =AND(B1>0,B1>LARGE($B$1:$N$1,4))
    ...and set the pattern format to blue.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    Lightbulb Re: VBA selecting top 3

    Hello JB,

    I've tried to work with Conditional Format but had too much trouble with finding the color numbers for further analysis.

    Greetings.
    Last edited by roberto1111; 10-29-2009 at 07:59 AM.

  4. #4
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: VBA selecting top 3

    ......................

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA selecting top 3

    Quote Originally Posted by roberto1111 View Post
    Hello JB,

    I've tried to work with Conditional Format but had too much trouble with finding the color numbers for further analysis.

    Greetings.
    Um...what does that mean?

  6. #6
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    Smile Re: VBA selecting top 3

    Quote Originally Posted by JBeaucaire View Post
    Um...what does that mean?

    It means like this;

    http://www.cpearson.com/excel/CFColors.htm

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA selecting top 3

    Sounds like you have a path. That's good.

    For what it's worth, there's ALWAYS more mathematically logical ways to evaluate data than by coloring. Whatever logic people use to paint and color cells, that same logic can be inserted directly into formulas and analysis...skipping the coloring thing altogether.

    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].

  8. #8
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    Talking Re: VBA selecting top 3

    Hello again,

    As from one rocket scientist to another, can you advise me what kind of formula I should try to use for this?

    Thank you
    Last edited by roberto1111; 10-30-2009 at 09:51 AM.

  9. #9
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: VBA selecting top 3

    I've tried the conditional formatting with making the highest values bold but can't sort them on this just like I can't sort them on backcolor.

    Thank you for any help offered.
    Last edited by roberto1111; 10-30-2009 at 10:02 AM.

  10. #10
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: VBA selecting top 3

    Since you are looking at the largest values, can't you just sort the data descending? All the largest values will be at the top...
    Remember what the dormouse said
    Feed your head

  11. #11
    Registered User
    Join Date
    10-06-2009
    Location
    Diemen, The Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    87

    Thumbs up Re: VBA selecting top 3

    Hello RomperStomper,

    Sorting the data in descending order is a good alternative.
    Only the difficulty for me is that values are inserted to another sheet where they then should be sorted in descending order for further analysis.

    I will open a new post on this, thank you for the suggestion.

    Greetings,

    Roberto

+ 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