VBA for counting specific texts from different ranges.

  • Hi , Urgently need your help on here.


    I have an worksheet that having different categories and i need a VBA for counting the texts by category wise. Following is the details


    I have A raw with the categories A,B,C, D, E , F and i have the texts like approved, rejected, hold etc... in raw number H. I will have to count these texts by category and texts in the second worksheet like below. Appreciate your help here, thanks...

    CategouryABC
    Approved331
    Rejected112
    Hold001
  • It would be easier to help and suggest a possible solution if you could post a copy of your file.

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • Place this formula in cell B2 of the "Summary" sheet: =COUNTIFS(WorkSheet!$H$2:$H$153,Summary!$A2,WorkSheet!$A$2:$A$153,Summary!B$1)
    Then drag it across to column G. Next select the range B2:G2 and drag that down to row 14. Please note that the ranges in the formula include the rows down to row 153. Change the 153 to suit your needs.

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • Try:

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • Quote

    But it is not running automatically. Is there any settings needs to be changed to run it automatically? Kindly advise.

    I'm not sure what you mean by this. Can you clarify in detail what you mean by "running automatically"?

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • Quote

    I mean, when I add or change the values in worksheet, the counting's are not updating in summary automatically.


    Copy and paste the following macro into the worksheet code module. Do the following: right click the tab for your "Worksheet" sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Change any value in column A or column H and exit the cell and the "Summary" sheet will update automatically. If you want to trigger the macro by only changing column A and not column H, then revise the range: Range("A:A,H:H").

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • Awesome. Working perfectly. Thank you very much for your help.


    Just one thing noticed that mouse cursor browsing for few seconds once I add or change the values in A & H. Is that normal thing?..

  • It just means that it's taking the macro a few seconds to process the data. The larger the data base, the longer it takes.

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • Noted. My File size is larger & kindly update me if you find anything to solve it in future.
    Thank you very much for your fantastic help to solve my issue.

  • You are very welcome. :)

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • Try this, it should be faster for a large data set. Macro will only fire if change is made to CATEGORY or STATUS columns and only if neither is blank for the row where data has been entered.


    Make sure you copy/paste both procedures!

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Sorry, I forgot to say that Cells B1 to G1 on the Worksheet sheet must be filled with header values, for the sample file I simply used Head 2, Head 3, Head 4 etc. The actual values do not matter, nor does it matter if additional columns have headers, as long as CATEGORY is always Column A and STATUS Column H then the code will work.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Are you talking about it not working with the sample file or your actual file?


    I am attaching your sample file where the code works fine for me.


    If it fails in your actual file then the line that errors indicates that there must be an entry in the Status column of the data worksheet that does not match one of the values in column A of the Summary table. A leading or trailing space in any entry would be seen by Excel as not matching even though the text appears to be the same.

  • Hi, It is working perfectly. Thank you.


    Just an inconvenience found that whenever i change the values, there is an notification coming by saying that summary file has been updated. Any way to remove this notification please?

  • You're welcome.


    At the very end of the code there is a line

    Code
    MsgBox "Summary has been successfully updated.", 64, "Completed."


    Either delete that line or comment it out (by placing an aposthrophy (') at the start of the line), that will stop the notification.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • You're welcome

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!