+ Reply to Thread
Results 1 to 13 of 13

COUNTIF function across columns, worksheets

  1. #1
    Registered User
    Join Date
    10-14-2012
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    8

    COUNTIF function across columns, worksheets

    Hi everyone,

    I'll try my best to explain this, but may need to take a screenshot. I have data that I need to sort and and do counts for multiple factors. I am sorting into various spreadsheets manually (i.e., putting year 1995 in one workbook, year 1996 in another workbook, etc.) because it is a large dataset. Within each year workbook, I need to do some sorting of the data into separate spreadsheets, which is fine. So my situation is:

    - I have 3 separate study areas (A, B, C) - one in each column. I use =COUNTIF(A2:Ax, "A"), etc. to get the count of cases in each study area. Then, I need to get the count of cases in each study area for male and for female (e.g., =COUNTIF(A2:Ax, "A", B2:Bx, "male"). Once this is done, I need to get the count of cases for each study area, for each age group, then within the age groups for males and for females (e.g., first for age group =COUNTIF(A2:Ax, "A", C2:Cx, "23") then the 2 rows following this would be for males 23 and females 23 =COUNTIF(A2:Ax, "A", C2:Cx, "23", B2:Bx, "male"). And I need to do each age year separately if there are cases that fall in that age (so basically each year from 0-84 and then anything 85+ is lumped together).

    I'm wondering if there is a way that I can drag across rows or down columns to make things easier. So as of now, for each gender/age, I have to keep the variables the same, but change the study area name, or if I go down columns I keep the study area name the same, but have to change age or age and gender. I have 11 years of records to do this for and a few hundred thousand total cases, so I'm just seeing if there is a way I can do this more efficiently. Thanks in advance

    Now that I'm working on it again - it's basically how I can keep some of the factors (such as study area) constant, but easily change other values down the column (such as age, or gender, or both).

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: COUNTIF function across columns, worksheets

    Hi wernie,

    Welcome to the forum.

    Suggest you to upload a sample workbook to support your query. Thanks.

    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), [email protected]

  3. #3
    Registered User
    Join Date
    10-14-2012
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: COUNTIF function across columns, worksheets

    Thanks DILIPandey. I created a mock spreadsheet with the data that I have, so for each different number under 'PD' I will be creating a new, smaller spreadsheet from the huge dataset. Obviously, the number of cases will vary for each PD, but I just created what would fit in the screenshot for this example. Excel_Screenshot.jpg

    Hopefully this helps it make a bit more sense! Thanks

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: COUNTIF function across columns, worksheets

    if you have the workbook, why not upload that instead of a picture? you may just get a picture back with your answer in it
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Registered User
    Join Date
    10-14-2012
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: COUNTIF function across columns, worksheets

    Quote Originally Posted by FDibbins View Post
    if you have the workbook, why not upload that instead of a picture? you may just get a picture back with your answer in it
    Sorry, new here as you can tell!

    I've attached the example workbook - hopefully that works. Thanks for that.Excel_ExampleWorkbook.xlsx

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: COUNTIF function across columns, worksheets

    see if this is what you need?

    if you want to include workbooks in this, that could probably be done through indirect()
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    10-14-2012
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: COUNTIF function across columns, worksheets

    @FDibbins

    Thanks - that looks like what I need to be doing! So then this leads me to a few questions (sorry, I am definitely not an Excel expert!):

    - When you populated the cells did you have to type out those formulas, or can you just drag across rows/down columns with the way you've typed it out?
    - I'm not quite sure what you mean by the workbooks and indirect (), but that may relate to my second question - when I create a new spreadsheet for the next set of records with new PD - is there a way to easily 'transfer' this so it will just automatically populate the cells based on those formulas for study area/age/gender?
    - Because in one spreadsheet it may specify A2:A22, but another it might only be A2:A5, so is that possible to do so?

    Thanks again, I really appreciate it! :D
    Last edited by Cutter; 10-17-2012 at 04:31 PM. Reason: Removed whole post quote

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: COUNTIF function across columns, worksheets

    to your 1st question. yes you can copy them down just like i have them. you may have noticed when you opened the file, i had a range high-lighted. this is a 3-row range for your age group - total, m,f. when you add more age ranges, copy these 3 rows together to the next range, they all reference the age group on the "total" row. so if you copy them all together, you wont need to mess with the references

    regarding your 2nd question about the different workbooks, if you just intend to copy/paste that entire sheet, to another file, why not keep them all in the same workbook, and just use new worksheets (tabs) each time? that way, you can just copy the format each time and change the data.

    doing it that way, you could even, if you wanted, have a summary of all sheets

    if you really do want to create new workbooks (files) for each set of records, i "think" you should just need to copy/paste the tables each time. but i still think new worksheets would serve you better

  9. #9
    Registered User
    Join Date
    10-14-2012
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: COUNTIF function across columns, worksheets

    Great, thanks! I am gonna have a play around with it and see how I go....I might end up back here with another question or two, but I'm excited to try this out.

    Oops - I did mean new worksheets I'll have new worksheets for each new PD code within the same year but then new workbooks (new files) for the different years to help better sort all of the data.
    Last edited by Cutter; 10-15-2012 at 11:45 AM. Reason: Removed whole post quote

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: COUNTIF function across columns, worksheets

    ok great. shout if you need more help with anything.

    1 thing i would suggest tho, is to try and keep the format (length/width) of each worksheet consistant - even if it goes down way below the data you have (in essence you will use a "template" for each new sheet). that way, if you want to do a summary, specific data will be in the same row/column/cell on each sheet, making a summary a breeze

  11. #11
    Registered User
    Join Date
    10-14-2012
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: COUNTIF function across columns, worksheets

    Thanks - I think that is actually along the lines of what I was going to ask because I just copied the formulas/format of what you had in the example into one of my new worksheets and had to change around where it was referencing the cell for "A" or "B" etc. so I was thinking perhaps I should just have that table (essentially a template as you say) to the right of all of the data? I know that the data will always be that fixed width because those are the only columns I have, but it will be highly variable on number of rows.

    Is that basically what you mean? So then if I have it starting in column R, for example, I know that each worksheet will have the same template starting in column R, then I can list out every single age year with male/female and it will either come up with 0 or populate with numbers if there are cases, but it will be consistent across each worksheet then and I can just copy/paste from one to the next. I will definitely want to be doing summaries so if I can set it up now so that will be easier in the long run that would be fantastic.

    Thanks again!

    PS - I'm originally from PA

  12. #12
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: COUNTIF function across columns, worksheets

    yup thats exactly what i meant with multiple "similar" sheets, constancey if often the key to keeping things simple and easy to work with. if its a big issue with having too many open/blank lines on a particular sheet because your data doesnt go down that far...hide some rows

    If this answered your question, please take a moment to mark the thread as "solved" - it helps keep things neat and tidy lol, and consider adding the reputation to those that helped (see points 2 & 3 below)
    if you still have questions regarding this thread, fire away

  13. #13
    Registered User
    Join Date
    10-14-2012
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: COUNTIF function across columns, worksheets

    Thanks. So I suppose one more quick (and probably easy) question would be how would I then go about doing summary sheets from all of the sheets with the count totals that were created from that template?

    Also, is there a way I can custom filter or sort so it will group/only show all codes under 'PD' in a certain range....for example - all codes that start with '740' or '81' etc. Because I need it to pick up 740, but then also codes like 7402, 74035, etc. Not sure if this should be a new subject, or if it is okay to post here Thanks!
    Last edited by Cutter; 10-21-2012 at 11:47 AM. Reason: Removed whole post quote

+ 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