+ Reply to Thread
Results 1 to 15 of 15

Count If Non-Contiguous Formula - How can I drag this down?

  1. #1
    Banned User!
    Join Date
    09-26-2015
    Location
    Manchester
    MS-Off Ver
    2013
    Posts
    218

    Count If Non-Contiguous Formula - How can I drag this down?

    Hi All,

    I have the following COUNTIF formula which serves to count only those cells where the formula (in aforementioned cell) returns a value i.e. this formula ignores those cells where the formula returns no value (as you know COUNTA is not suitable to count non-blank cells with formulas as it always counts cells with formulae in).

    =SUM(COUNTIF(INDIRECT({"I7","L7","O7","R7","U7"}),">"""))

    I need this formula to be active on over 2,000 rows. The first row I need it in is row 7 (hence the cell references above) and then I attempted a simple drag down exercise for the next 2,000 rows however, after dragging the formula down it became clear to me that the row references in this formula (I7, L7, O7, R7 & U7) were not changing with the rows. Is there any quick way to overcome this problem as I don't fancy changing 2,000 formulae manually.

    Thanks in advance

  2. #2
    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,946

    Re: Count If Non-Contiguous Formula - How can I drag this down?

    as you know COUNTA is not suitable to count non-blank cells with formulas as it always counts cells with formulae in
    agreed, but COUNT() will only count values - will that help?

    What exactly are you trying to do here?

    COUNTIFS() may help too?
    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

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count If Non-Contiguous Formula - How can I drag this down?

    Try it like this...

    =SUMPRODUCT(--(MOD(COLUMN(I7:U7)-COLUMN(I7),3)=0),--(I7:U7<>""))
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Banned User!
    Join Date
    09-26-2015
    Location
    Manchester
    MS-Off Ver
    2013
    Posts
    218

    Re: Count If Non-Contiguous Formula - How can I drag this down?

    So to give you more detail:

    - Columns G, H & I: G and H contain non numeric data e.g "C2" & "B1". Column I contains a concatenate formula e.g. "C2 B1"
    - Columns J, K & L: J and K contain non numeric data e.g C2. Column L contains a concatenate formula e.g. "C2 B1"
    - Columns M, N & O: M and N contain non numeric data e.g C2. Column O contains a concatenate formula e.g. "C2 B1"
    - Columns P, Q & R: P and Q contain non numeric data e.g C2. Column R contains a concatenate formula e.g. "C2 B1"
    - Columns S, T & U: S and T contain non numeric data e.g C2. Column U contains a concatenate formula e.g. "C2 B1"

    Column G & H and so on are primary and secondary stock code locations e.g. C1 = Container 1 and B2 = Shelf 2. Column I and so on is the full stock location e.g. Shelf 2 in Container 1.
    The five groups (Group 1 = G, H and I, Group 2 = J, K & L etc. etc.) represent a stock location. So on the basis that one row represents one unique stock item, I will first use Group 1 to record the first stock location. If there are so many units that the stock item must be contained in two locations (two shelves) then Group 2 will be used to show the second location and so on and so forth.

    COUNT doesn't work because the data is non-numerical.

    Tony Valko, your formula doesn't work presumably for a similar reason, although using your formula returns a result of 5 regardless of whether there is any value returned in the concatenate cells or not, whereas FDibbins formula returns a value of zero (again regardless of whether there is a value in the concatenate cells or not).

  5. #5
    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,946

    Re: Count If Non-Contiguous Formula - How can I drag this down?

    upload a small (clean) sample workbook (not a pic) of what you are working with, and what your expected outcome would look like.

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,370

    Re: Count If Non-Contiguous Formula - How can I drag this down?

    Tony's formula works as far as I understand your requirement.

    E.G. With "C2 B1" in various cells (I, L, O,R,U) I get the correct count for each row.

  7. #7
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count If Non-Contiguous Formula - How can I drag this down?

    Quote Originally Posted by STUARTXL View Post
    Tony Valko, your formula doesn't work presumably for a similar reason
    The formula I suggested will count cells in the range I7, L7, O7, R7, and U7 that are NOT blank.

    If that's not what you wanted then I misunderstood.

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Count If Non-Contiguous Formula - How can I drag this down?

    Is there anything common in a header row in those columns I L O R and U ?
    So we can say something like
    Count Text Strings in Row 7, if the Header in Row 1 = "SomeCommonString" ?

    Something like
    =COUNITFS(I$1:U$1,"SomeCommonString",I7:U7,"?*")
    Last edited by Jonmo1; 06-08-2016 at 02:28 PM.

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,370

    Re: Count If Non-Contiguous Formula - How can I drag this down?

    Tony's formula works as far as I understand your requirement.

    E.G. With "C2 B1" in various cells (I, L, O,R,U) I get the correct count for each row.

  10. #10
    Banned User!
    Join Date
    09-26-2015
    Location
    Manchester
    MS-Off Ver
    2013
    Posts
    218

    Re: Count If Non-Contiguous Formula - How can I drag this down?

    Hi All,

    Not been able to load this website for a couple of hours. I wanted to edit my post to contain the below paragraph (see below bold comment) but since there have been more replies. I've also attached a simple version of my worksheet. Can I take liberties by drawing your attention to the macro query too? (Thanks!!!!)

    My formula is in Column V and aims to count the number of locations that each item is stored in. The reason I need this information is because I eventually want to create a macro that, on a separate tab (that also contains the 2,000 lines of stock items) will generate x number of lines below each row that the stock item is contained in, with 'x' being the number in Column V. If anyone can help with this, that would be even better...one can dream...


    FYI the attached contains 4 tabs:
    1 - 'CurrentIssues' shows the formula suggested by Tony and FDibbins doesn't work (seen some comments that say it does so wanted to demonstrate it doesn't on mine)
    2 - 'StockLocation - HowItShouldWork' demonstrates the values that Column V should display
    3 - 'StockCount' is a spreadsheet I want to use to conduct stock counts (this is the macro part). Basically I need a list to use for my monthly stock counts where I can input the unit numbers at each location. But as our stock stores are very fluid and items can be moved from one location to another on a quarterly basis, I require this sheet to be linked to the 'StockLocation' sheet
    4 - 'StockCountExample1' just shows you how I would use the 'StockCount' list to conduct a stock take.
    Attached Files Attached Files

  11. #11
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count If Non-Contiguous Formula - How can I drag this down?

    Ok, the problem is that the cells may appear to be blank but they are not. They contain a single space character due to the formula =cell&" "&cell.

    So, try this version:

    =SUMPRODUCT(--(MOD(COLUMN(I7:U7)-COLUMN(I7),3)=0),--(LEN(I7:U7)>1))

  12. #12
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Count If Non-Contiguous Formula - How can I drag this down?

    Try

    =COUNTIFS($G$6:$U$6,"Full Location",G7:U7,"<> ")


    The problem you've been having is your 'Blanks' are not really blank (even by formula blank standards)
    They contain a space, resulting from this formula
    =G7&" "&H7

  13. #13
    Banned User!
    Join Date
    09-26-2015
    Location
    Manchester
    MS-Off Ver
    2013
    Posts
    218

    Re: Count If Non-Contiguous Formula - How can I drag this down?

    Thanks guys.

    Everyone on here amazes me. I've worked with Excel at a basic level for years but been learning like crazy this past year to really advance my skills. And just when I thought I'd got to a competent level, I look at how quickly you all solve solve problems and it just astounds me. Such an obscure problem in my formula and you pick it up so quickly.

    Both solutions work perfectly. Does anyone know how to create that Macro I referred to?

  14. #14
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Count If Non-Contiguous Formula - How can I drag this down?

    You're welcome.

  15. #15
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count If Non-Contiguous Formula - How can I drag this down?

    Thanks for the feedback!

    Unfortunately, I'm not much of a programmer!

+ 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] Count Contiguous cells only
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 09-16-2015, 01:27 PM
  2. [SOLVED] Drag down an count if formula and skip by 12 rows
    By johnnypol in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 01-23-2014, 10:41 AM
  3. [SOLVED] How to sum non-contiguous columns applied as a formula on contiguous cells
    By figo12 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 10-09-2013, 01:07 PM
  4. How to count contiguous columns in a single row
    By danieldowds in forum Excel General
    Replies: 8
    Last Post: 10-22-2012, 09:13 AM
  5. Count number of unique entries in a range and drag formula
    By pedrofogao21 in forum Excel General
    Replies: 2
    Last Post: 03-22-2012, 11:31 AM
  6. Count contiguous zeros
    By jasonanthony in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-14-2008, 03:35 PM
  7. How do I count non-contiguous cells?
    By broush in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-30-2006, 06:20 PM

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