Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Need a Formula (Sum Dynamic)

0

Hi, I want get total value of given Date Range.

Ex :  May-2011 to Jun-2012 should be answer is 287

Thanks

Answer
Discuss

Discussion

Thanks your Reply.

Can you pls put the correct formula and upload the file ?
Iy you want to change Years & Months to change format, you can do it.

Thsnks
Neranjan
Neranjan (rep: 2) Aug 10, '20 at 6:04 am
Add to Discussion

Answers

0
Selected Answer

You need the DATEDIF() function. This is a legacy function for which Excel doesn't display the usual intellisense information but it works. This is the syntax:

=DATEDIF([Start Date], [End Date],[Interval])

The Interval is one of these strings:-

"m" = months
"d" = days
"y" = years

Therefore the function your are looking for might be

[F15] = DATEDIF(C13, C18, "m")

That would return a result of 13, if C13 and C18 were dates, which they are not. It could never be 455 even if you were to change "m" in the formula to "d" because even 14 months have only 426 days at the most, and your dates - if they were dates - don't have days at all.

Obviously, you need the DATE() function which has this syntax.

=DATE([Year], [Month],[Day)

Now I ask you to make a little test. In C12 of your sample worksheet enter this formula:

[C12] =DATE(A3,5,C3)

C12 will display 14 May, 2011 in the short form you have set in the Regional Settings of your computer, perhaps 14/05/2011 or 5/15/2011. Now enter =C$12 in H13 and copy the formula to H14. The same date will appear in both cells. Now right-click on H13 and select Format Cells... from the drop-down menu.

  1. Select the Numbers tab
  2. Select Custom in the Categories list.
  3. Change the format mask you see in the Type field to yyyy
  4. Repeat the same for H14 but write mmm in the Type field.

Now the display in H13:H14 is the same as C13:C14 but for each of the cells you have a complete date - in fact the same date for both cells, despite their very different appearance - that you can do calculations with. 

Discuss

Discussion

Hi Neranjan, You are right. My answer was insufficient. I have expanded on it in the workbook which is now attached above. Please pay attention to the handling of the days. I have included both start and end months in the calculation of time lapsed. My explanations should help you implement your own preference.
Variatus (rep: 4889) Aug 10, '20 at 9:34 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login