+ Reply to Thread
Results 1 to 10 of 10

Counting and adding instances in a cell range

  1. #1
    Registered User
    Join Date
    01-02-2012
    Location
    Arkansas
    MS-Off Ver
    Excel 2007
    Posts
    12

    Counting and adding instances in a cell range

    Forum, I'm currently using the code
    Please Login or Register  to view this content.
    to count the number of instances of VA in a group of cells. When I enter 8VA and 3VA, the calculation will add them up to be 11VA, which is perfect. However it grabs and adds the first number only, so if I enter 12VA and 11VA, I get 3VA instead of 23VA. Can the calulation be changed to add numbers greater than 9?
    Thank you for your help.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Counting and adding instances in a cell range

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook. Don't upload a picture when you have a workbook question. None of us is inclined to recreate your data. Upload the workbook and manually add an 'after' situation so that we can see what you expect. In addition clearly explain how you get the results..
    To attach a file to your post, you need to be using the main 'New Post' or 'New Thread' page and not 'Quick Reply'.
    To use the main 'New Post' page, click the 'Post Reply' button in the relevant thread.

    On this page, below the message box, you will find a button labelled 'Manage Attachments'.
    Clicking this button will open a new window for uploading attachments.

    You can upload an attachment either from your computer or from another URL by using the appropriate box on this page.
    Alternatively you can click the Attachment Icon to open this page.

    To upload a file from your computer, click the 'Browse' button and locate the file.

    To upload a file from another URL, enter the full URL for the file in the second box on this page.
    Once you have completed one of the boxes, click 'Upload'.

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-02-2012
    Location
    Arkansas
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Counting and adding instances in a cell range

    Thanks TMShucks. I've attached a dummy workbook containing an input spreadsheet called Schedule and a calculations spreadsheet called Calculations. You'll see on the calculations worksheet that the code is identifying and adding up 11VA and 12VA to be 3VA instead of 23VA. I would like the code to add up double-digit entries.

    As background: This is being used to track multiple schedule entries for staff. 12VA = 12 hours of vacation, 8CH = 8 hours of company holiday, and so on. The code works perfect for recognizing the alpha and numeric characters, except for double digit entries.
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    Office 2021
    Posts
    2,237

    Re: Counting and adding instances in a cell range

    if you always have "VA" in cells , one way is,

    =SUMPRODUCT(--SUBSTITUTE(0&LOWER(Schedule!A2:B2),"va",""))
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

  5. #5
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Counting and adding instances in a cell range

    Hi

    You take your solution, using two helper columns

    Hope to helps you.
    Attached Files Attached Files
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  6. #6
    Registered User
    Join Date
    01-02-2012
    Location
    Arkansas
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Counting and adding instances in a cell range

    Thanks, but no, I'm using about 5 different alpha combinations: VA, CH, PC, SI, etc.

  7. #7
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Counting and adding instances in a cell range

    ...Believe that your answer is not for my solution..
    Last edited by Fotis1991; 01-19-2012 at 06:46 PM.

  8. #8
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    Office 2021
    Posts
    2,237

    Re: Counting and adding instances in a cell range

    With CTRL+SHIFT+ENTER, rather than just ENTER

    =SUM(IFERROR(--SUBSTITUTE(UPPER(Schedule!A2:B2),{"VA";"CH";"PC";"ST"},""),0))

    Enter your all alpha combination in UPPER case separated by colon ;

  9. #9
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Identifying and adding elements in a cell range

    RockyRoad,

    Give this a try:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  10. #10
    Registered User
    Join Date
    01-02-2012
    Location
    Arkansas
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Counting and adding instances in a cell range

    Apologies. I spreadsheet I attached failed to provide all the information you needed. There is additional data, such as timeframes worked, in the cells also. I've attached a more comprehensive dummy workbook with multiple data entry types. I've tried the suggestions above to no effect. I hope this new spreadsheet provides a better scope for my need. Thank you for the time you've given.
    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)

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