+ Reply to Thread
Results 1 to 20 of 20

CountBlank for "Adaptive" Range

  1. #1
    Registered User
    Join Date
    03-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    21

    Question CountBlank for "Adaptive" Range

    I am trying to count a range for blank cells using CountBlank(), however, the range I need to use is, for example, "A:A".
    When I specify an entire column, however, I get a massive number of blank cells.

    Is there a way to tell CountBlank to only return the number of blanks that have data in adjacent columns?

    This is an issue because sometimes I need to count A1:A234 but another day my data my span from A1:A500 for example.

    Thanks!

  2. #2
    Valued Forum Contributor
    Join Date
    12-25-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2016
    Posts
    506

    Re: CountBlank for "Adaptive" Range

    Hi, try this formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.




    _______________________________________________________________________________________________________________________________
    1. Click on the * Add Reputation if you think someone helped you
    2. Mark your thread as SOLVED when question is resolved

    Alvin

  3. #3
    Registered User
    Join Date
    03-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: CountBlank for "Adaptive" Range

    Hi Alvin,

    For some reason that isn't working for me.
    Also, I was hoping to not have to specify another range. Otherwise, I can just use:

    Please Login or Register  to view this content.
    Thanks,

  4. #4
    Valued Forum Contributor
    Join Date
    12-25-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2016
    Posts
    506

    Re: CountBlank for "Adaptive" Range

    You'll need to specify another range (i.e. B:B) because your criteria is to verify whether there's any data in adjacent column.
    Sure, you can use COUNTIFS too but probably SUMPRODUCT would be slightly faster (I guess)



    _______________________________________________________________________________________________________________________________
    1. Click on the * Add Reputation if you think someone helped you
    2. Mark your thread as SOLVED when question is resolved

    Alvin

  5. #5
    Registered User
    Join Date
    03-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: CountBlank for "Adaptive" Range

    Makes sense. I was just wondering if there was a way to have Excel intelligently only calculate cells that are part of your dataset and not the entire possibly number of cells in a column.

    Thanks,

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

    Re: CountBlank for "Adaptive" Range

    Quote Originally Posted by alvin-chung View Post
    you can use COUNTIFS too but probably SUMPRODUCT would be slightly faster (I guess)
    COUNTIFS is more efficient.

    In this application:

    =COUNTIFS(A:A,"",B:B,"<>")

    =SUMPRODUCT(ISBLANK(A:A)*NOT(ISBLANK(B:B)))

    The COUNTIFS is magnitudes more efficient.

    COUNTIFS will only calculate up to the used range even if it's referencing the entire columns.

    SUMPRODUCT will calculate EVERY cell it references.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  7. #7
    Registered User
    Join Date
    03-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: CountBlank for "Adaptive" Range

    Thanks Tony, good to know I was approaching it right. Still wish there was a way for Excel to intelligently ignore data outside of your dataset but I guess that is asking too much (there are probably few reasons why someone would want to include all blank cells up to Excel's limit in their formulas lol)

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

    Re: CountBlank for "Adaptive" Range

    Is there a way to tell CountBlank to only return the number of blanks that have data in adjacent columns?
    Be more specific. What is the range of adjacent columns?

    Can you post a SMALL sample file that demonstrates what you want to do?

    SMALL = about 20 rows worth of data

  9. #9
    Registered User
    Join Date
    03-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: CountBlank for "Adaptive" Range

    I already have my answer. Excel does not treat rows as records within a dataset.
    Within Access, for example, if you ask to return the number of records within a column that are not blank, Access is smart enough to know that you don't mean "all of the cells that COULD be blank".
    If I tell Excel to count blanks for A:A, and my dataset only spans from A1:B12, Excel will return blanks for the maximum blank cells that a column contains (65,000+)

    Make sense?

  10. #10
    Valued Forum Contributor
    Join Date
    12-25-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2016
    Posts
    506

    Re: CountBlank for "Adaptive" Range

    Quote Originally Posted by Tony Valko View Post
    COUNTIFS will only calculate up to the used range even if it's referencing the entire columns.
    SUMPRODUCT will calculate EVERY cell it references.
    Thanks for highlighting, you're right and the explanation were very useful!
    Plus, I just did an experiment by disabling multi-threaded calculation and get 2'10 for SUMPRODUCT and 2'03 for COUNTIFS



    _______________________________________________________________________________________________________________________________
    1. Click on the * Add Reputation if you think someone helped you
    2. Mark your thread as SOLVED when question is resolved

    Alvin

  11. #11
    Valued Forum Contributor
    Join Date
    12-25-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2016
    Posts
    506

    Re: CountBlank for "Adaptive" Range

    Not sure if this helps, you can try name your data as a table and use the name in your formula.



    _______________________________________________________________________________________________________________________________
    1. Click on the * Add Reputation if you think someone helped you
    2. Mark your thread as SOLVED when question is resolved

    Alvin

  12. #12
    Registered User
    Join Date
    03-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: CountBlank for "Adaptive" Range

    When I use countif, it doesn't only calculate within the used range . . .

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

    Re: CountBlank for "Adaptive" Range

    Post a SMALL sample file so we can see what you're trying to do.

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

    Re: CountBlank for "Adaptive" Range

    Try this experiment.

    Follow these steps exactly. Do not deviate.

    Open a new workbook

    Enter this formula in C1:

    =COUNTIF(A:A,"")

    That is the same as COUNTBLANK(A:A) except it only calculates the used range.

    Right now the used range is A1:C1 and the COUNTIF formula returns 1.

    Enter an X in A10.

    The used range is now A1:C10 and the formula correctly returns the result 9. There are 9 blank cells from A1:A10.

    Press function F5
    Click the Special button
    Select: Last Cell
    OK

    Excel takes you to cell C10, the last cell in the used range.

    Now, enter an X in A25.

    The COUNTIF function now counts the empty cells from A1:A25.

  15. #15
    Registered User
    Join Date
    03-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: CountBlank for "Adaptive" Range

    Tony, my countif statement returned 65536
    I am using Excel 2010. Perhaps there is a setting to control this functionality? That is what brought me here to the forum was that Excel is not including just the "used range". Previously, Excel was doing so (on my old computer from another job)

    Here's a screenshot:

    countif.png

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

    Re: CountBlank for "Adaptive" Range

    65536 just happens to be the number of rows in a *.xls file.

    Are you opening a *.xls file in Excel 2010?


  17. #17
    Registered User
    Join Date
    03-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: CountBlank for "Adaptive" Range

    Hmm, good catch. It turns out my Excel was stuck on "Compatibility Mode".
    I've since turned it off but my countif function still calculates the maximum number of blanks (now 1,048,576).
    I followed the same process . . .

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

    Re: CountBlank for "Adaptive" Range

    Well, at this point I'm out of suggestions without being able to see what you're trying to do in context of a file.

  19. #19
    Registered User
    Join Date
    03-19-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: CountBlank for "Adaptive" Range

    There must be some sort of setting that controls this. If we're both using Excel 2010 then they should work in the same way.
    Thanks for your help, I will track down the setting separately.

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

    Re: CountBlank for "Adaptive" Range

    Good deal. Thanks for the feedback!

+ 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. Replies: 5
    Last Post: 01-23-2014, 11:02 AM
  2. if Range("A1") = "Mike" Then Range("A1") = "michael" Then Exit Sub
    By a8015945 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-30-2013, 10:08 AM
  3. [SOLVED] Sheets("Sheet2").Range("AA1") = "Note"
    By dcburkejr in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-03-2012, 04:10 PM
  4. Problem using "Cells" in "Range" "400" error
    By johnnywinter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2009, 05:46 PM
  5. use variable in Workbooks("book1").Worksheets("sheet1").Range("a1"
    By Luc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2005, 04:05 PM

Tags for this Thread

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