Counting Number of Months between Two Dates in Excel - excel

So I am attempting to simply count the number of months bewtween an earlier date and today, which will be in the B:B column; once the number of months have been counted, the result is then multiplied by 28, then added back to the original date. Note the requirement: Result >= Today, so basically if the result is less than today it needs to add another 28 days. The current formula I made only works if the dates are in the current year (and I am not 100% sure if this formula works, it appears to so far though.)
Here is my defunct formula, but maybe someone can get a general idea from my above comments and the below formula of what I am attempting to achieve here:
=IF(B89="","",IF(I89="X","LEG",IFERROR(IF((MONTH(TODAY()-B89)*28)+B89<TODAY(),(MONTH(TODAY()-B89)*28)+B89+28,(MONTH(TODAY()-B89)*28)+B89),"Future")))
Thank you in advance for your assistance!
Note: I just want to point out that the reference to I89 is insignificant in the above. I just didn't want to remove it in case I deleted the wrong parenthesis or some other typo, so I decided to leave in there. So basically you would not need to necessarily worry about the first two "IF" statements, nor the IFERROR, unless you just wanted to!
2ND EDIT: Okay I decided to strip down formula, original post's formula is above, the stripped version below:
IF((MONTH(TODAY()-B89)*28)+B89<TODAY(),(MONTH(TODAY()-B89)*28)+B89+28,(MONTH(TODAY()-B89)*28)+B89)

You should not use MONTH() for this purpose as this will lead to wrong results in some cases, and certainly when the B89 date is in another year.
Instead see how many days you are past the last multiple of 28 days since B89, and go back to that date (by subtracting), and then add another 28 to it:
=TODAY() + 28 - MOD((TODAY()-B89), 28)
The earliest date this can give is the date of tomorrow. If today should be an acceptable outcome of the formula, then replace TODAY() with TODAY()-1, which results in this formula:
=TODAY() + 27 - MOD((TODAY()-1-B89), 28)

How about something like this:
=IF(B89="","",IF(I89="X","LEG",IF(IF(B89<=TODAY(),B89+28*IF(AND(B89<TODAY(),TEXT(B89,"mmyy")=TEXT(TODAY(),"mmyy")),"1",(TEXT(TODAY(),"yy")*12+MONTH(TODAY()))-(TEXT(B89,"yy")*12+MONTH(B89))),"Future")<TODAY(),TODAY(),IF(B89<=TODAY(),B89+28*IF(AND(B89<TODAY(),TEXT(B89,"mmyy")=TEXT(TODAY(),"mmyy")),"1",(TEXT(TODAY(),"yy")*12+MONTH(TODAY()))-(TEXT(B89,"yy")*12+MONTH(B89)))))))
Got a little long now, but you have a lot of criteria :)

Related

Excel Consecutive Days with at least 60 minutes worked

I have project worksheet. Each day I track how many minutes I work on different tasks.
How could I create a formula that counts the number of consecutive days where the total minutes is greater than 60?
The part the part I"m stuck on is the consecutive days part.
I believe this is possible but could someone point me in the correct direction?
Here is how you can achieve this directly:
=MAX(FREQUENCY(IF(B4:B10>=60,ROW(B4:B10)),IF(B4:B10<60,ROW(B4:B10))))
Paste the formula on B1 in your case and press CTRL+SHIFT+ENTER (not just ENTER). You will see an array (curly braces like this {} will appear before and after the formula automatically once you press CTRL+SHIFT+ENTER)
I'm assuming you want to include 60 also. Feel free to modify accordingly.
Note: Update the range as you require.
I think this problem is more complicated than it looks at first. The following formula could give a correct result:
=SUMPRODUCT(((B2:B8>=60)+(B2:B8<60)*(B4:B10>=60))*(B3:B9>=60))

date dependent cell reference

I was hoping someone might be able to point me in the right direction, I'm trying to automate a section of a spread sheet which shows a persons planned hours of work against the hours they actually did. The data is sourced from a worksheet which is broken down into months and departments.
Is there a way to get the reference table on the main dashboard to vlookup/index a certain column dependent on the computers date?
I.E. for May it will look in the planned and actual hours column for may and then in June it will search the June column for the same data.
Normally I would post some code but I'm not even sure where to begin on this one.
You mention VLOOKUP in you question.
To use this in VBA use, WorksheetFunction.Vlookup(), but it seems you could avoid VBA altogether if you wanted. Here are some formulas of interest:
If you want to search months by the current date, you can use this kind of vlookup (or MATCH() or HLOOKUP() if these are columns as you indicate)
=VLOOKUP(TEXT(TODAY(),"mmmm"),Range,1,FALSE)
Use "mmm" if you use 3-letter months
If months are in static column number can be taken from using the MONTH() function.
=MONTH(TODAY())
"index a certain column dependent on the computers date?"
=TODAY() gets computer's date.
I would tend to use MATCH() to get the months column (in this example I've assumed months are in row 1)
=MATCH(TEXT(TODAY(),"mmmm"),1:1,0)
You can then use INDIRECT() to match a specific month column and department row (if in a 2D format), or SUMIFS() with INDIRECT() if you want to sum hours.
As in:
=INDIRECT("'Sheet'!R" & MATCH("department_name",A:A,0) & "C" & MONTH(TODAY()), FALSE)
Thank you for all the help in regards to this problem, unfortunatly I could not quite get my head round the suggestions which have been put forward, though I have been able to solve this problem (although it is a messy solution)
=IF($F$95="March",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,2,FALSE),
IF($F$95="April",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,3,FALSE),
IF($F$95="May",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,4,FALSE),
IF($F$95="June",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,5,FALSE),
IF($F$95="July",VLOOKUP(D97,'Planned Hours'!$A$1:K37,6,FALSE),
IF($F$95="August",VLOOKUP(D97,'Planned Hours'!$A$1:K37,7,FALSE),
IF($F$95="September",VLOOKUP(D97,'Planned Hours'!$A$1:K37,8,FALSE),
IF($F$95="October",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,9,FALSE),
IF($F$95="November",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,10,FALSE),
IF($F$95="December",VLOOKUP(D97,'Planned Hours'!$A$1:$K$37,11,FALSE)))))))))))
But it works. Again thanks to all that lent a hand.
--EDIT--
By the way this is not in VBA in the end.

Array IF formula to transpose calendar days returns #N/A on last day of the month

I created the following formula to create a calendar based on the users month entry selection.
{=IF(COLUMN($M$5:$AT$5)-COLUMN($M$5)+1>SUMPRODUCT(0+(WEEKDAY(ROW(INDIRECT($L$6&":"&EOMONTH($L$6,0))),1)<8)),"",TRANSPOSE(SMALL(IF(WEEKDAY(ROW(INDIRECT($L$6&":"&EOMONTH($L$6,0))),1)<8,ROW(INDIRECT($L$6&":"&EOMONTH($L$6,0)))),ROW(INDIRECT("1:"&EOMONTH($L$6,0)-$L$6)))))}
The formula works great, however, the last day of the month returns #N/A. No matter what month the user enters, the last day returns the error. Here is a sample using December (I hid columns to save the space):
As you can see, every day works except the last one. I thought it was because there were 31 days, so I used a month with 30 days:
Same result. There is got to be something wrong with the formula, but I can't figure out why.
I can't promise to dissect your formula in its entirety, though I will tell you the reason for your error (by the way, I would've thought this would produce a #REF! error, not #N/A - can you clarify?)
If the date in L6 is the end of the month, then this part (at the end of your formula):
=ROW(INDIRECT("1:"&EOMONTH($L$6,0)-$L$6))
will resolve to (since the end of the month pertaining to the entry in L6 is, in this case, precisely the same as the value in L6):
=ROW(INDIRECT("1:"&0))
which is:
=ROW(INDIRECT("1:0"))
and, since 1:0 is not a valid range reference, this part errors (though errors with #REF!, which is why I asked you about this).
Regards

SumProduct Not Working with Date Values

So I am trying to come up with a ranking system that will start at 1, and increment for every different client we have, and reseting each month.
Heres what I have:
=SUMPRODUCT(--([Client]=[#[Client]]), --([Receive Date]> [#[Receive Date]]) )+1
When this is entered, a #VALUE is returned to the cell, however, when I use
=SUMPRODUCT(--([Client]=[#[Client]]), --([Sales Rep]> [#[Sales Rep]]) )+1
Or another column (that is not a date) everything seems to work out fine. Although, obviously, that makes the ranking on a rep by rep and client basis rather than month.
Any suggestions as to why the date column isn't working and how to fix it?
Edit: Oops, forgot to include this, since I want to reset the ranking every month, I have another column that concatenates the month and year, so a Receive Date of 3/10/2014 would become "3 2014".
Then I use the:
=SUMPRODUCT(--([Client]=[#[Client]]), --([Concat Date]> [#[Concat Date]]) )+1
And thats where things get squirrelly.
Edit 2:
Alright, so I think I figured out the formula, which I constructed in this dummy workbook. Everything works perfectly here! But when I copy and paste it into the actual workbook I'm using, the #VALUE error pops up. I've checked the formatting of each corresponding column from my test file to my real one. Has me totally stumped, thoughts?
Now that you added in the edit of Concat Date, it makes sense... My belief is that you probably are creating that field as text rather than a date and so your comparison operatir will no longer work.
So, suppose your sheet had your dates in column A beginning in A2 - You could create the Concat Date field using the following formula:
=DATE(YEAR(A2),MONTH(A2),1)
OR
=EOMONTH(A2,-1)+1
In effect, it will give you the first day of the month for any date BUT it will still be a date, so your comparison operator will still work.
PS - You can still use cell formatting to make it look like `3 20141 if you really wanted to, but the most important part is that it is a date value so you can use it for comparisons!!
Hope this does the trick!!

Compare if year in date is prior to today's year

I have a date in the format of "4/26/2013". I want to see if that date is prior than the current year, whatever that current year may be (don't want to hardcode 2013) and count how many of the rows match that criteria. Say there are 6 rows of dates in that format:
=COUNTIF(C2:C7, YEAR(Today()))
This threw an error. I'm new to Excel, so I probably made a huge mistake! Can anyone see what is wrong with this?
Thanks!
If C2:C7 contain dates you need to compare them to the 1st of January in the current year, e.g.
=COUNTIF(C2:C7,"<"&DATE(YEAR(TODAY()),1,1))
or you can use SUMPRODUCT like this
=SUMPRODUCT((YEAR(C2:C7)<YEAR(TODAY()))*(C2:C7<>""))
I just figured it out. My syntax was wrong. The answer to the above example was:
=COUNTIF(C2:C7, ">"&YEAR(TODAY()))
That returned the number of dates in C2 - C7 that were prior to the current year.

Resources