+ Reply to Thread
Results 1 to 14 of 14

count values in one range if the cells in a corresponding range are not empty

  1. #1
    Registered User
    Join Date
    06-08-2020
    Location
    wales
    MS-Off Ver
    2019
    Posts
    9

    count values in one range if the cells in a corresponding range are not empty

    Hello, I've got stuck and can't find the answer anywhere...

    I have a data set from a survey which tells me how many people of different age ranges they have in their household.

    In order to calculate the number of households with adults between 16 and 64 and dependents who are under 16, I would like to use a forumula that counts all the instances where there is a value in columns D to G (green in the attached), i.e. each household IF there is a value in the corresponding cells A to B (yellow in the attached).

    I'm pretty sure I should be able to do this but have tried all sorts, to no avail.

    Here are some of the forumals I've tried:

    =IF(D2:G875,"<>"),AND(B2:C875,"<>"),COUNT(D2:G875)

    =IF(B2:C875,"<>"),counta(D2:G875)

    =countif(D2:G875,"<>"),(B2:C875,"<>")

    These all return a 'There's a problem with this formula' errors.

    Can anyone help?

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: count values in one range if the cells in a corresponding range are not empty

    K2 =countif(K2:K20,">0") => is result

    K3 =if(SUM(A2:B2)=0,"",SUM(A1:G2)) and drag down.

    See the attached file.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: count values in one range if the cells in a corresponding range are not empty

    There's a little contradiction between what you ask and what your formula shows.
    You say "IF there is a value in the corresponding cells A to B"

    But your formula is taking B:C as the condition of not being empty.

    Anyway if I understand you correct - here is the formula you need to apply:
    J2 =IF(AND(A2<>"",B2<>""),SUM(D2:G2),"")

  4. #4
    Registered User
    Join Date
    06-08-2020
    Location
    wales
    MS-Off Ver
    2019
    Posts
    9

    Re: count values in one range if the cells in a corresponding range are not empty

    I realised that was confusing after posting- the spreadsheet i posted was just a small extract from a much larger dataset I'm working with, and the columns in the formula refer to the larger dataset.

    I couldn't get your formula to work. when i paste
    =IF(AND(A2<>"",B2<>""),SUM(D2:G2),"")
    directly, it doesn't do anything at all (no results and no error message, the formula just sits in the cell).
    I tried typing it, but same thing happened.

    I played around a little and it brought up a FALSE result but that's seems to be the result regardless of whether there are values in both ranges.

    I've attached in case that makes any sense of it.

    I think from bost the responses so far I've understood that i need to go line by line and then count up, rather than trying to do all the rows at once.

    BTW, I don't want to add up the values, I just want to count each row as 1 (or true) if it has values in a or b AND values in c or d or e or f or g

    basically, does the household have any adults between 16-54 AND any children between 0-15
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-08-2020
    Location
    wales
    MS-Off Ver
    2019
    Posts
    9

    Re: count values in one range if the cells in a corresponding range are not empty

    I don't want to add up the values, I just want to count each row as 1 (or true) if it has values in a or b AND values in c or d or e or f or g

    basically, does the household have any adults between 16-54 AND any children between 0-15 (if so 1 or TRUE, if not 0 or FALSE

    Does that make it any clearer?

    Thank you!

  6. #6
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: count values in one range if the cells in a corresponding range are not empty

    Did you tried my formula in #2.

    In this example this are 8 familys with childeren <16 (A or B) and a member < 65 year (in C : G)

  7. #7
    Registered User
    Join Date
    06-08-2020
    Location
    wales
    MS-Off Ver
    2019
    Posts
    9

    Re: count values in one range if the cells in a corresponding range are not empty

    Oh yes! It works, I'm sorry I didn't figure out your logic, but now I have and it does work. Thank you so much!

  8. #8
    Registered User
    Join Date
    06-08-2020
    Location
    wales
    MS-Off Ver
    2019
    Posts
    9

    Re: count values in one range if the cells in a corresponding range are not empty

    What I need to do now is count adults 16-54 with no children under 16 and no adults over 55.

    I've tried to adjust the formula you gave me, but it doesn't seem to be working - are you able to help with this?

    Thanks!

  9. #9
    Registered User
    Join Date
    06-08-2020
    Location
    wales
    MS-Off Ver
    2019
    Posts
    9

    Re: count values in one range if the cells in a corresponding range are not empty

    Don't worry, I've figured it out!

  10. #10
    Registered User
    Join Date
    06-08-2020
    Location
    wales
    MS-Off Ver
    2019
    Posts
    9

    Re: count values in one range if the cells in a corresponding range are not empty

    actually, it's not working properly.

    So what I need is to count every household where there is at one or more child under 16 AND one or more adults 16-54 AND one or more adults over 55

    I also need to count hosueholds where there is one or more adults 16-54 AND one or more adults over 55 but NO children under 16

    your help greately appreciated as always

  11. #11
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: count values in one range if the cells in a corresponding range are not empty

    M2 =IF(OR(SUM($A2:$B2)=0,SUM($C2:$G2)=0,SUM($H2:$I2)=0),"","yes")

    O2 =IF(OR(SUM($C2:$G2)=0,SUM($H2:$I2)=0),"","yes")

    Both results are zero

    M1 =Countif(M2:M20,"yes")

    O1 =Countif(O2:O20,"yes")


    See the attached file.
    Last edited by oeldere; 06-09-2020 at 07:40 AM.

  12. #12
    Registered User
    Join Date
    06-08-2020
    Location
    wales
    MS-Off Ver
    2019
    Posts
    9

    Re: count values in one range if the cells in a corresponding range are not empty

    thanks for your reply.

    So in the sheet attached I have included column G in the third category (over 55 - blue colour).

    To explain a bit more, what I would like for scenario 1:
    count every household where there is at one or more child under 16 AND one or more adults 16-54 AND one or more adults over 55
    so for exmaple, row 17 in the attached should be counted (and not 0).

    For scenario 2
    households where there is one or more adults 16-54 AND one or more adults over 55 but NO children under 16

    row 11 in the attached should be counted (and not 0)

    Does that make sense?
    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: count values in one range if the cells in a corresponding range are not empty

    M2 =IF(OR(SUM($A2:$B2)=0,SUM($C2:$F2)=0,SUM($G2:$I2)=0),"","yes")

    O2 = IF(AND(SUM($A2:$B2)=0,SUM($C2:$F2)>0,SUM($G2:$I2)>0),"yes","")


    Make sure the answer you give, meet the conditions. (row 11 don't meet the conditions).

    See the attached file
    Last edited by oeldere; 06-09-2020 at 09:58 AM.

  14. #14
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: count values in one range if the cells in a corresponding range are not empty

    Glad I could help.

    Thanks for marking the question solved.

+ 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. Sum of empty (or zero) cells in a range of two values
    By exadus in forum Excel Formulas & Functions
    Replies: 21
    Last Post: 10-09-2019, 04:41 PM
  2. [SOLVED] insert values into empty cells in a range only
    By Ramzes in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-26-2018, 12:24 PM
  3. Return corresponding values for cells in a range not empty
    By EBos in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-19-2017, 12:49 PM
  4. How to make a named range null or empty if count = 0 (no values present)
    By MCunningham in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-15-2013, 12:12 PM
  5. [SOLVED] Transfer cells range to another sheet if first cell of destination range is empty
    By kopapa in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 11-04-2013, 04:32 PM
  6. [SOLVED] find unique values in a range that contains text and empty cells
    By bombicci in forum Excel General
    Replies: 4
    Last Post: 07-04-2012, 09:17 AM
  7. Count the number of cells in a range that are not empty
    By efernandes67 in forum Excel General
    Replies: 5
    Last Post: 07-23-2010, 05:41 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