+ Reply to Thread
Results 1 to 16 of 16

Counting cells by group

  1. #1
    Registered User
    Join Date
    06-03-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    5

    Counting cells by group

    Hi o/

    First post here. Wanted to ask here as whenever I google for excel help, a lot of the time the best answers I get are from this forum. This time however, I'm stumped (or tired).

    qwe.PNG

    In the example above, I have a tracker I use at work to monitor holidays, absence, etc. The red cells with a 4 relate to absence. I can count how many days absence easy enough with countif and I get 4 for example on line 26, but I also want to count the number of periods of absence, which in this case would be 3.

    Can' think how to do this? I could merge the cells, but then I lose the ability to count the total days?

    Thanks in advance for any help you folks can provide
    Last edited by StevieW; 06-03-2016 at 05:10 AM.

  2. #2
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,228

    Re: Counting cells by group

    Try this ...

    =COUNTIFS(B26:X26,"1",C26:Y26,"")

  3. #3
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,061

    Re: Counting cells by group

    Phuocam beat me to it, but as I put the file together I'll post it anyway.

    BSB
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    06-03-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    5

    Re: Counting cells by group

    That's brilliant, thank you both very much.

    Can't say as I fully understand why it works, but I'm at work and rushing so will make it make sense at home tonight!

    Thanks again, both very helpful, and thanks also BSB for the file

    Edit : Lightbulb moment! It counts the occurrences of the end of the group, ie any 1's with only blank cells afterwards! Easy when you know how!
    Last edited by StevieW; 06-03-2016 at 05:05 AM.

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2509 (Windows 11 Home 24H2 64-bit)
    Posts
    92,809

    Re: Counting cells by group

    The COUNTIFS function has to fulfil both criteria: in other words, it is counting only the ultimate cell in each range, as the next cell has to be blank (""). It's a nifty trick!
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Volunteer organiser & photographer with the Sutton Hoo Ship's Company: https://saxonship.org/
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,061

    Re: Counting cells by group

    It works by counting the number of cells in a range that are contain a 1 but have a blank cell to the right of them. Notice the two ranges in the formula are offset by 1 column.
    So if you have 3 cells in a row with a 1 in them it's only counting the last one as this one has a blank cell to the right and ignoring the other two as they do not have a blank cell to the right.

    Hopefully that helps explain it a little.

    BSB

  7. #7
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,061

    Re: Counting cells by group

    Quote Originally Posted by AliGW View Post
    It's a nifty trick!
    Nifty indeed!
    Sadly I cannot take the credit for it. I pinched it off daddylonglegs many moons ago when I was trying to do exactly the same thing at work.
    http://www.excelforum.com/excel-form...-in-excel.html

    BSB

  8. #8
    Registered User
    Join Date
    06-03-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    5

    Re: Counting cells by group

    Christ, you folks are quick, beat my edit

    Found a problem though in the way I would use. I use other references, such as "4" for annual leave. If there is a 4 after a 1, it wouldn't work would it? Any way to make it so it only counts if NOT a 1?

  9. #9
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,061

    Re: Counting cells by group

    Here you go.

    BSB
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    06-03-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    5

    Re: Counting cells by group

    Of course! Thanks again I like it here lol

  11. #11
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,061

    Re: Counting cells by group

    Quote Originally Posted by StevieW View Post
    I like it here lol
    Me too. That's why I spend so much time here even when I'm meant to be working!

    BSB

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2509 (Windows 11 Home 24H2 64-bit)
    Posts
    92,809

    Re: Counting cells by group

    Devil's advocate: what if there is one day of leave immediately after a period of absence???

    PS I like it here, too, but only get to visit often when I'm NOT at work!!!

  13. #13
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,061

    Re: Counting cells by group

    Quote Originally Posted by AliGW View Post
    Devil's advocate: what if there is one day of leave immediately after a period of absence???
    You've lost me there...

    BSB

  14. #14
    Registered User
    Join Date
    06-03-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    5

    Re: Counting cells by group

    The "<>1" addition to the second range in the countifs solves that, doesn't it?

  15. #15
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,061

    Re: Counting cells by group

    Quote Originally Posted by StevieW View Post
    The "<>1" addition to the second range in the countifs solves that, doesn't it?
    I don't know as I'm not 100% sure what AliGW meant...

    BSB

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2509 (Windows 11 Home 24H2 64-bit)
    Posts
    92,809

    Re: Counting cells by group

    Quote Originally Posted by BadlySpelledBuoy View Post
    You've lost me there...

    BSB
    Quote Originally Posted by StevieW View Post
    The "<>1" addition to the second range in the countifs solves that, doesn't it?
    Quote Originally Posted by BadlySpelledBuoy View Post
    I don't know as I'm not 100% sure what AliGW meant...

    BSB
    I was having a blonde moment ... Just ignore me.

    Sorry, boys!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] (VBA) How Assign Column Cell To Corresponding Group, and Paste Group Cells into Groups WS?
    By eryksd in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-08-2016, 06:18 PM
  2. Replies: 0
    Last Post: 10-21-2014, 03:20 PM
  3. VBA to search a group of cells and input a message if a value is missing from the group
    By ntaylor652 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-19-2014, 05:30 AM
  4. Replies: 0
    Last Post: 02-04-2013, 03:25 PM
  5. Replies: 19
    Last Post: 05-26-2011, 04:15 PM
  6. Replies: 1
    Last Post: 02-17-2011, 04:05 AM
  7. Replies: 7
    Last Post: 10-18-2007, 11:03 AM

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