+ Reply to Thread
Results 1 to 16 of 16

Count if, display results in msgbox

  1. #1
    Registered User
    Join Date
    10-03-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    25

    Count if, display results in msgbox

    Hi all, I am unsure if this will be easier if I just used a formula and displayed the results in a cell. But here is what I wish to achive:

    In cells D:D, I have a 'loop refrence' which can be A, B, C, D or E. The data is inserted sequentially so A,A,A,A,A,A,B,B,B,C,C,C,C,C. The refrence could finish at any letter, so it may only have two loops, so column D:D may consist of A,A,A,A,A,A,B,B,B,B,B. Hope this is making sence so far.

    In loop A, 1 piece of equiptment is stored per cell in column M:M e.g.
    A, MAC
    A, Smoke
    A, Sounder
    A, MAC
    A, MAC

    I want a messagebox to display how many 'MACs', 'Smoke', and 'Sounders' are in each seperate loop. e.g.
    Loop A
    34 MACs
    3 Smokes
    2 Sounders

    LoopB
    2 MACs
    6 Smokes
    7Sounders

    Hope this is clear enough, thanks in advance for any help!

  2. #2
    Registered User
    Join Date
    10-03-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Count if, display results in msgbox

    Has anyone got any suggestions?

    Thanks

  3. #3
    Registered User
    Join Date
    10-03-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Count if, display results in msgbox

    Could anyone suggest a way or starting this off? Or how to count IF in VBA code, thanks.

  4. #4
    Registered User
    Join Date
    10-03-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Count if, display results in msgbox

    any suggestions at all are welcome

  5. #5
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Count if, display results in msgbox

    Quote Originally Posted by j9070749 View Post
    Hi all, I am unsure if this will be easier if I just used a formula and displayed the results in a cell.
    I wouldn't mind helping, but can you supply a sample workbook and at least for me, it may be easier to display in a cell versus a message box.

    On second thought, have you considered a pivot table?
    HTH
    Regards, Jeff

  6. #6
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: Count if, display results in msgbox

    Maybe you could upload an example.
    Kind regards, Harry.

  7. #7
    Registered User
    Join Date
    10-03-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Count if, display results in msgbox

    I don't have the spreadsheet I'm working on, but I have attaches an example one. Hope this makes it easier to understand.

    Thanks
    Attached Files Attached Files

  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,929

    Re: Count if, display results in msgbox

    see if the attached is something you can work with?

    it does not use macros, and the "loop" list will grow as you add more

    edit: revised by adding a pivot table as a 2nd alternative
    Attached Files Attached Files
    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

  9. #9
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Count if, display results in msgbox

    See how this works for you and a big thanks to Moo for giving me a helping hand (and a good set of eyes).
    Attached Files Attached Files

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Count if, display results in msgbox

    Another method for building this type of table is to use the Dictionary Object, e.g:

    Please Login or Register  to view this content.
    You could iterate the Dictionary and write straight back to Sheet rather than use Array, however, less to / fro Worksheet / VBE using the Array (ie single update).

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

    Re: Count if, display results in msgbox

    My take on Jeffrey's "use a formula" method, I like it because it's loopless and uses the autofilter:

    Please Login or Register  to view this content.
    _________________
    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!)

  12. #12
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Count if, display results in msgbox

    Well Merry Christmas to me and the OP and thank you so much for the assist. I woke up this morning not knowing what to expect and as usual you guys came through with sharing your experience/knowledge.

    @Luke, I've studied the scripting dictionary and love it, but at the same time, always confused by it. I've stepped through your sample quite a few times and it is sinking in ever so slowly. When first running the example it seems a variable was missed in the declaration, v, so I added it as a variant. Is this the correct declaration?

    @Jerry, I initially looked into the advanced filter, but when two columns where involved I scraped the idea, but now seeing how you used the concatenate and THEN the advanced filter, I should have thought longer and harder. It seems you may have left a piece of testing code behind in the form of...

    Please Login or Register  to view this content.
    Thanks again to all. I have learned so much from you and hope to continue...

    God Bless and Merry Christmas to all...

  13. #13
    Registered User
    Join Date
    10-03-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Count if, display results in msgbox

    Thankyou very much for the help all the solutions work great!

  14. #14
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Count if, display results in msgbox

    You are most welcome. We are all glad to have helped and happy you have a solution to work with.

  15. #15
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Count if, display results in msgbox

    Quote Originally Posted by jeffreybrown View Post
    @Luke, I've studied the scripting dictionary and love it, but at the same time, always confused by it. I've stepped through your sample quite a few times and it is sinking in ever so slowly. When first running the example it seems a variable was missed in the declaration, v, so I added it as a variant. Is this the correct declaration?
    Error on my part - I modified my original (stored .bas) but failed to modify the Variant from vStr to v so yes the above is correct. Apologies for oversight but good to know people are running Option Explicit

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

    Re: Count if, display results in msgbox

    Try
    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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