+ Reply to Thread
Results 1 to 6 of 6

using dates in IF statement

  1. #1
    Registered User
    Join Date
    08-28-2008
    Location
    Edmonton
    Posts
    6

    using dates in IF statement

    I have a problem that I cannot seem to figure out.

    I have data in column A1 and B1 I also have a date in column G1

    What I need to be able to determine is, if the date falls within particular month, then the data from columns A1 and B1 need to be added together and put into the corresponding month column. The months Jan - Dec are in sep columns on the right from T1 thru AE1. I tried to use a simple IF statement to see if it could determine if the date was between the beginning and end of the month but I have either done something wrong in the formula or dates don't work with IF statements.

    I used in the January column =if(G1<Jan1,if(G1>Jan31,(+a1+b1),""),"")
    I changed the dates to Feb for the Feb column and so on.... The date in the G1 column did not matter if it was between or outside the dates for the month, the formula just returned an empty cell.


    Any help would be appreciated.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi, and welcome to the forum.

    Are you using proper date 'numbers' suitably formatted, or just pieces of text that say "Jan1, Feb1" etc? If not that's your error.

    Upload the workbook, or at least a representative sample of it and no doubt someone will take a look and advise.

    Rgds

  3. #3
    Registered User
    Join Date
    08-28-2008
    Location
    Edmonton
    Posts
    6
    I have attached a sample of what I am attempting to accomplish. My dates in G! are formatted correctly, but the dates in my formula are being treated like cell positions. I don't know how to tell the formula to check the "date".

    Help please!!
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    08-28-2008
    Location
    Edmonton
    Posts
    6
    I have done some poking around on the site and I believe that i have found the answer to my question. It helps being able to search once you are a member!

    I have put the formula together using the actual date code instead of the way I was doing it and I have added the AND function to simplify the formula.

    I am now using the following for January: =if(and(G1>=39814,G1<=39844),(A1+B1),"")

    This is a great resource and I will check back often to see if I can be of help or shoot any problems that I may stumble across!!

    Thanks:

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    It's probably better, and more transparent to use dates in the formula rather than the serial numbers, i.e.

    =if(and(G1>=DATE(2009,1,1),G1<=DATE(2009,1,31)),A1+B1,"")

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Whilst your dates in col G are proper date numbers, your dates in row 1 are just text, which is what I was originally querying.

    See the attached modified Sample workbook. I've entered month ending dates in J1:N1, and formatted K1 to show you that you can still display it as "Jan" rather than 31/1/2009 if you wish. Change the other cells in row 1 accordingly.
    The important point to note is that you must use proper date numbers if you want to use them in calculations or tests.

    I've also modified the formula in K2:M2 to show you what I think you're looking for. The original formula had #Refs when I opened the workbook.

    HTH
    Attached Files Attached Files

+ 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. if statement using a range of dates?
    By strikeofdawn in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-11-2008, 05:20 PM
  2. Using If statement with multiple dates and criteria
    By Excel_user123 in forum Excel General
    Replies: 1
    Last Post: 05-22-2008, 07:37 PM
  3. Extracting data from dates.. use an IF statement?
    By howsyourdad? in forum Excel General
    Replies: 5
    Last Post: 08-09-2007, 06:30 AM
  4. IF Statement Question dealing with Dates
    By lilsnoop in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-14-2007, 05:32 PM
  5. IF Statement Question dealing with Dates
    By lilsnoop in forum Excel General
    Replies: 8
    Last Post: 05-10-2007, 08:32 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