+ Reply to Thread
Results 1 to 5 of 5

Thread: COUNTIF will not read date from reference cell

  1. #1
    Registered User
    Join Date
    06-29-2011
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2007
    Posts
    4

    COUNTIF will not read date from reference cell

    I have the formula set up like this:

    =COUNTIF(RFI!O:O,"<6-27-11")

    It works fine, but I would rather have it set up like this:

    =COUNTIF(RFI!O:O,"<F5") where F5 = 6-27-11

    Unfortunately, the result is now wrong. How do I make it work for a reference rather than typing the date in the formula?

  2. #2
    Registered User
    Join Date
    06-29-2011
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: COUNTIF will not read date from reference cell

    To clarify, the correct result is 18 and it shows up as 1 when using the reference cell.

  3. #3
    Forum Guru Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007 and 2010
    Posts
    1,207

    Re: COUNTIF will not read date from reference cell

    Hi and welcome to the forum.

    Try it like this:

    =COUNTIF(RFI!O:O,"<"&F5)
    Hope that helps,

    Colin

    RAD Excel Blog

    Other tutorials:
    Array Formulas | Deleting Rows with VBA

  4. #4
    Registered User
    Join Date
    06-29-2011
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: COUNTIF will not read date from reference cell

    It worked! Thanks Colin, would you mind explaining the logic of "<"&F5 ?

  5. #5
    Forum Guru Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007 and 2010
    Posts
    1,207

    Re: COUNTIF will not read date from reference cell

    Sure...

    & is the concatenation operator: it joins strings together. So, for example:

    "hello " & "the" & " world"
    becomes:
    "hello the world"

    With your original try:
    =COUNTIF(RFI!O:O,"<F5")

    COUNTIF is trying to count any cells which have a value less than the string "F5". It is not trying to count any cells which have a value less than the value in the F5 cell. It doesn't realise that you want it to refer to cell F5, because "F5" is a string, not a range reference.

    To work around this, you can concatenate the string "<" to the value in the F5 cell, like this:
    "<"&F5


    In this case, F5 contains the date 27 June 2011. In Excel, dates are stored as numbers under the hood, and I expect that the numeric equivalent of 27 June 2011 in your Excel will be 40721.

    So, if F5 contains the date 6-27-11, "<"&F5 would return this string: "<40721".
    COUNTIF can then correctly assess column A for any values which are smaller than 40721.
    Hope that helps,

    Colin

    RAD Excel Blog

    Other tutorials:
    Array Formulas | Deleting Rows with VBA

+ 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.2.0