We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

Excel IF function (with date)

Hello I'm making a sreadsheet to use for budgeting.

I've used an IF function so that if the date next to the cell is the same as a specific date that I've entered into a separate cell then it changes the calculation values.

Just simple IF(D2=A12,500,0) or that sort of thing.

However I also want to use an IF function for a date but just based on the month.

As in if the month of the date in cell D2 is May or 05.

However I haven't managed to figure out how to do it.

Basically I want it so that whenever it is a particular month (regardless of the year), the calculation changes. However it needs to base this off the full date in the adjacent cell. Is there a way of getting it to read the month ignoring the year.

(It's complicated because I've got the dates in the spreadsheet set to change whenever I input the 'current date' into a cell, so the formulas need to be able to adapt to the changes and still do the correct calculations for the dates)
Mortgage remaining: £42,260 of £77,000 (2.59% til 03/18 - 2.09% til 03/23)

Savings target June 18 - £22,281.99 / £25,000

Comments

  • esuhl
    esuhl Posts: 9,409 Forumite
    Part of the Furniture 1,000 Posts Name Dropper
    It's been a while, but isn't there a month() function that would take care of that?
  • Le_Kirk
    Le_Kirk Posts: 24,865 Forumite
    Part of the Furniture 10,000 Posts Photogenic Name Dropper
    Have a look at the first link: -
    https://support.office.com/en-us/article/Date-and-time-functions-reference-fd1b5961-c1ae-4677-be58-074152f97b81
    and then the second. It is complicated but if you start with the date calculation first, make sure that works and then build the rest of your calculation round it.
    https://support.office.com/en-us/article/Calculate-the-difference-between-two-dates-8235e7c9-b430-44ca-9425-46100a162f38
  • System
    System Posts: 178,365 Community Admin
    10,000 Posts Photogenic Name Dropper
    =IF(MONTH(D2)=5,<true value>,<False value>)

    This works if D2 gets its date from another cell I.E. D2 content is something like '=A4')
    This is a system account and does not represent a real person. To contact the Forum Team email forumteam@moneysavingexpert.com
  • FreddieFrugal
    FreddieFrugal Posts: 1,752 Forumite
    Part of the Furniture 1,000 Posts Name Dropper
    edited 4 November 2015 at 1:29PM
    Yes that works, ha! Thanks for the quick responses. I was actually just popping back on to say I found it myself on a webpage somewhere in the end.

    formula in the end to make this whole thing work is:

    =IF(D2>=$A$26,($A$2*($A$16/12))+($A$2-$A$6)-($A$22+(IF(MONTH(D2)=$A$12,$A$10,0))),($A$2*($A$8/12))+($A$2-$A$4)-($A$14+(IF(MONTH(D2)=$A$12,$A$10,0))))

    :eek:

    But yes it's using IF(MONTH(D1)=3,5,0)

    meaning If the month in cell D1 is 3 (March) then use value 5, if not use 0

    But I've used it like IF(MONTH(D1)=E5,5,0)

    So that I can alter the month that it's looking for if it changes in the future, by altering the number in cell E5
    Mortgage remaining: £42,260 of £77,000 (2.59% til 03/18 - 2.09% til 03/23)

    Savings target June 18 - £22,281.99 / £25,000
  • esuhl
    esuhl Posts: 9,409 Forumite
    Part of the Furniture 1,000 Posts Name Dropper
    formula in the end to make this whole thing work is:

    =IF(D2>=$A$26,($A$2*($A$16/12))+($A$2-$A$6)-($A$22+(IF(MONTH(D2)=$A$12,$A$10,0))),($A$2*($A$8/12))+($A$2-$A$4)-($A$14+(IF(MONTH(D2)=$A$12,$A$10,0))))

    :eek:

    If you end up with complicated formulae that might be hard to debug, it's sometimes worth breaking up the problem into smaller chunks and using multiple columns showing your "working out", rather than one column that magically calculates the final answer. You can hide the columns that only show the "working out". Just a thought...

    It's very easy to run out of space with formulae, as you can only use 255 characters (unless MS have fixed that in later versions of Excel).

    You can also name ranges of cells; sometimes it helps readability if you use range names rather than cell references.
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 351.7K Banking & Borrowing
  • 253.4K Reduce Debt & Boost Income
  • 454K Spending & Discounts
  • 244.7K Work, Benefits & Business
  • 600.2K Mortgages, Homes & Bills
  • 177.3K Life & Family
  • 258.4K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16.2K Discuss & Feedback
  • 37.6K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.