+ Reply to Thread
Results 1 to 14 of 14

CountIF Across Different Sheets

  1. #1
    Registered User
    Join Date
    10-31-2016
    Location
    Melbourne
    MS-Off Ver
    2013
    Posts
    6

    CountIF Across Different Sheets

    I am trying to count instances of a certain value across multiple sheets. It works if I do this:

    =COUNTIF('1002'!B2,1)+COUNTIF('1003'!B2,1)+COUNTIF('1004'!B2,1)+COUNTIF('1005'!B2,1)+COUNTIF('1006'!B2,1)

    But each time I add a new sheet (e.g., 1007), I have to update the formula across a large number of cells and conditions.

    Is there a way I can do something like this (paraphrasing):

    =COUNTIF('1002' through to '1100'!B2,1)

    so I can keep inserting sheets within the range 1002 - 1100 without having to update formulas?

    Cheers, Arthur

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,025

    Re: CountIF Across Different Sheets

    Not totally simple, but very do-able. Sheet references apply to my sample file.

    1. Save your file as macro enabled.

    2. Add a Named Range (CTRL-F3) called Sheets, referring to =TRANSPOSE(GET.WORKBOOK(1))&T(NOW())

    3. Add another named range, called Sheetlist, referring to =OFFSET(Master!$E$2,,,SUMPRODUCT(--(LEN(Master!$E$2:$E$100)>0)))

    4. use this array formula in Master E2. copy down to row 100.

    5. Use this formula in Master!A1: =SUMPRODUCT(COUNTIF(INDIRECT("'"&Sheetlist&"'! A1"),1))

    So, if there are more than 100 sheets, adjust the 100 in the formula at 3) and copy the formula at 4 down further.

    that's it. See file. if you andd another sheet, it'll add to the sheet list and, if A1=1, will be counted at Master!A1.

    Don't forget to enable macros when you open this file....
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,025

    Re: CountIF Across Different Sheets

    Dohh!

    i forgot to add:

    Array Formulae are a little different from ordinary formulas in that they MUST be confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER.

    You will know the array is active when you see curly braces { } appear around the outside of your formula. If you do not CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly braces yourself - it won't work...

  4. #4
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: CountIF Across Different Sheets

    Whilst I am in awe of Glenn's formula. I learnt something so thanks Glenn. There may be simpler options, if b2 is blank or 1 sum(1002:Endsheet'!b2) may suffice, if endsheet is a sheet that you always insert in front off. That way the formula just grows. If you also wish to extend the formula to sum other values, this obviously wont work, but is is not clear from the question how the data is structured

    Regards

    Dav

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,025

    Re: CountIF Across Different Sheets

    Davsth... very true!! However, as you said, your suggestion is so limited in its application; I went for a more general solution that'll work with all sorts of data.

  6. #6
    Registered User
    Join Date
    10-31-2016
    Location
    Melbourne
    MS-Off Ver
    2013
    Posts
    6

    Re: CountIF Across Different Sheets

    That is a very generous reply Glenn, thank you. I too am in awe - in fact, I am still mentally digesting it!

    In the meantime, I am playing with Dav's solution to see if I can get around it a simple way. I managed to get the sheet range working using SUM, but not COUNTIF.

    I have attached a sheet to show how the data looks.
    Each different sheet represents a different persons set of responses to a question.

    Sheet "Response Counts" cell B3 is the one in question. The formula in B3 needs to be copied down all relevant COUNT columns. Hope this makes sense.

    Appreciate your help!

    Arthur
    Attached Files Attached Files

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,025

    Re: CountIF Across Different Sheets

    It won't (can't) work with countif as it does not accept 3D references.

    I now have the sheet fully set up for you. Rules:

    1. Add on the individual response sheets to the right of the last response sheet.

    2. Do not move any of the other sheets to the right of ANY of the individual response sheets (you can probably hide them to prevent someone moving them by mistake).

    3. Think carefully. Will you need to add any more sheets (other than individual response sheets) to this? If so, DO SO NOW and re-post as one of the named ranges will need to be tweaked...

    4. Play with it and check it is giving the responses YOU expect. It's giving the responses that I think you expect!!!

    5. Enable macros on opening.

    happy to explain...
    Attached Files Attached Files
    Last edited by Glenn Kennedy; 11-01-2016 at 04:25 AM.

  8. #8
    Registered User
    Join Date
    10-31-2016
    Location
    Melbourne
    MS-Off Ver
    2013
    Posts
    6

    Re: CountIF Across Different Sheets

    Glenn, that is amazing! Perfect. Cant thank you enough.

    The only issue I had was the data in the first sheet (1002) was not getting picked up in the count.
    I got around it by creating a dummy sheet (called 'dummy') and now have this as the first sheet to the right of "Response Counts" sheet.
    It now all works perfect.

    I have decided to calling this workbook "Survey Analysis" and make its sole purpose nothing other than to analyse the survey data, so there will be no other sheets added to it other than survey response sheets (which I will just copy over from my main sheet).

    I like the way your formula works for incomplete sheets too. It is likely many of these sheets will not be completely filled in, but I still want the formula to count whatever is in there. So it works perfect for my purposes.

    Next question - what is the best way to send you pints of Guinness?

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,025

    Re: CountIF Across Different Sheets

    You're right.... There was an extra sheet on your posted sample (I'm on the phone now & can't remember what it was called). I deleted it and forgot to change the named range that uses the sheet list. I can tell you what changes to make; but kudos for figuring out a workaround!

    Regarding Guinness: at home I stick to my own bottled IPA. Off to the home of the black stuff for a couple of days tomorrow morning to go to a couple of gigs in some of Dublin's music clubs. I'll have had more than enough Guinness by Friday...

    Glad to have helped & thanks for the Rep (Guinness substitute).

  10. #10
    Registered User
    Join Date
    10-31-2016
    Location
    Melbourne
    MS-Off Ver
    2013
    Posts
    6

    Re: CountIF Across Different Sheets

    Hi Glenn,

    A while back you very generously helped me out with a COUNT function/script that allowed me to count responses to questions from multiple sheets.

    Well my data is now finally in, and I have entered it into the spreadsheet you set up for me (see link below - for some reason I cannot attach files here, or in PM with Chrome or IE).

    Now I have one problem - not all the sheets are being considered in the Response count sheet.
    I can isolate the problematic sheets if it helps.
    e.g., I know for a fact sheet 1004 is not being counted as that has a "6" entry in the 28th question for question 1, and that "6" is not counted in the "Response counts" sheet for Q28.

    Any help (again!) would be greatly appreciated.

    Cheers, Arthur

    Links:

    https://drive.google.com/file/d/0B5A...ew?usp=sharing

  11. #11
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,025

    Re: CountIF Across Different Sheets

    You have inserted two new columns into SOME of your data sheets (e.g. 1002,1003,1004,1005). (Columns B & C) with some sort of date-related function in them. You can't do that. The formula is not (will never be) clever enough to work tat out. Up to the column where the last of the data exists the column structure MUST be identical. So, if you do need those new columns, move them off to the right somewhere.

  12. #12
    Registered User
    Join Date
    10-31-2016
    Location
    Melbourne
    MS-Off Ver
    2013
    Posts
    6

    Re: CountIF Across Different Sheets

    Ahh...those columns were hidden...hidden from people like me! So I couldn't work out the problem. And I am sure I never would have.

    You are a gem, thank you again Glenn!

  13. #13
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,025

    Re: CountIF Across Different Sheets

    You're welcome. The good thing is I remembered the question and didn't have to waste a age figuring out what I'd done....



    If that takes care of your original question, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.

    It'd also be appreciated if you were to click the Add Reputation button at the foot of any of the posts of all members who helped you reach a solution.

  14. #14
    Registered User
    Join Date
    10-31-2016
    Location
    Melbourne
    MS-Off Ver
    2013
    Posts
    6

    Re: CountIF Across Different Sheets

    Good memory!

    And finally I get to now understand why I sub-consciously didn't mark the thread as 'solved' until now

+ 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. COUNTIF across sheets
    By cyber_killer in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-28-2018, 07:39 PM
  2. COUNTIF across sheets
    By legoman26 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-31-2015, 03:35 PM
  3. [SOLVED] COUNTIF in different Sheets?
    By gaino33 in forum Excel General
    Replies: 3
    Last Post: 07-30-2014, 09:25 AM
  4. [SOLVED] Countif using 2 sheets
    By Novice22 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-18-2012, 10:27 AM
  5. Countif Between Sheets
    By phoenixreal in forum Excel General
    Replies: 4
    Last Post: 09-26-2011, 12:21 PM
  6. countif in the last 5 sheets
    By aishaz_88 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-27-2007, 04:37 AM
  7. [SOLVED] COUNTIF across sheets
    By MaggieMagill in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-07-2005, 04:05 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