+ Reply to Thread
Results 1 to 7 of 7

count if in excel - can this be done

  1. #1
    Registered User
    Join Date
    10-05-2004
    Location
    Scarborough, ON
    MS-Off Ver
    Mac Office 2019 v16.30 (19101301)
    Posts
    72

    count if in excel - can this be done

    Hi,

    can this be done using countif
    you have three cities, Toronto (TOR), Calgary (CAL) and Vancouver (VAN) and you have ID tags for sites in those locations.
    column 'A' will have the cities, column 'B' will have the formula and column 'C' will have the list of sites.
    example
    A
    Calgary

    B
    2

    C
    (DON-CAL 10293 B)
    (DON-CAL 104759 C-5)

    and so forth

    please let me know if you would need a copy of raw data
    Regards
    Hemant - Owner
    http://www.hksltd.ca

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: count if in excel - can this be done

    If each location will be enclosed in parentheses, this regular formula returns the count of right-parentheses in Col_C
    B2: =LEN(C2)-LEN(SUBSTITUTE(C2,")",""))

    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Registered User
    Join Date
    10-05-2004
    Location
    Scarborough, ON
    MS-Off Ver
    Mac Office 2019 v16.30 (19101301)
    Posts
    72

    Re: count if in excel - can this be done

    I am not sure how to apply that to the spreadsheet. I have never used LEN before.

    Let me attach a sample file

    Attachment 155692
    Last edited by hemants; 05-14-2012 at 11:27 AM.

  4. #4
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: count if in excel - can this be done

    I misunderstood your example...I thought that one cell could contain more than one location.
    To do what you want, you'd need some way to define the city abbreviation so a formula like this would work:
    B5: =COUNTIF($C$1:$C$40,"*-VAN-*")

    That regular formula returns the count of Col_C items that contain -VAN-
    In your posted workbook, the count is: 12

    Is that something you can work with?

  5. #5
    Registered User
    Join Date
    10-05-2004
    Location
    Scarborough, ON
    MS-Off Ver
    Mac Office 2019 v16.30 (19101301)
    Posts
    72

    Re: count if in excel - can this be done

    yes, i adjusted it more

    =COUNTIF(E:E,"*CAL*")

    and it provides the results I needed. I was close when trying to figure it out i had the "*" on the outside of the quotes and not the inside

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: count if in excel - can this be done

    You might need to leave the dashes on either side of the city abbreviation to avoid counting cells that coincidently have that text.
    Example:
    (DON-MTL-AdvantageTours-Cab3) contains "van" but doesn't refer to Vancouver.

  7. #7
    Registered User
    Join Date
    10-05-2004
    Location
    Scarborough, ON
    MS-Off Ver
    Mac Office 2019 v16.30 (19101301)
    Posts
    72

    Re: count if in excel - can this be done

    Quote Originally Posted by Ron Coderre View Post
    You might need to leave the dashes on either side of the city abbreviation to avoid counting cells that coincidently have that text.
    Example:
    (DON-MTL-AdvantageTours-Cab3) contains "van" but doesn't refer to Vancouver.
    you logic is sound, ty again!

+ 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