rocksolid77
New Member
- Joined
- Sep 19, 2011
- Messages
- 18
Hi All, Any help will be greatly appreciated. Basically what I'm trying to do is to create a macro that can tell us how much time has passed between two dates. This can be accomplished with the following formula:
=YEAR(A2)-YEAR(A1)-IF(OR(MONTH(A2)<month(a1),and(month(a2)=month(a1), day(a2)<day(a1))),1,0)&"="" years,="" "&month(a2)-month(a1)+if(and(month(a2)="" <="MONTH(A1),DAY(A2)<DAY(A1)),11,IF(AND(MONTH(A2)<MONTH(A1),DAY(A2)">=DAY(A1)),12,IF(AND(MONTH(A2)>MONTH(A1),DAY(A2)<day(a1)),-1)))&" months,="" "&a2-date(year(a2),month(a2)-if(day(a2)<day(a1),1,0),day(a1))&"="" days"<="" pre=""> Where A2 is the most recent date
and A1 is the oldest date
and will return the answer in the following format x Years, X Months, X Days
What I'm trying to do is have this as a macro with input boxes and a MsgBox rather than have the actual calculations being done in the worksheet. Unfortunately I'm still very noob with VBA and am not sure how to go about this, or if it's even possible.
I assume I can just have the value of the input boxes added to cells on the spreadsheet, calculate it in the sheet and return the value of the cell as a message box but was hoping there was some way to do this without affecting the contents of the sheet.
There is an 8 year old thread on this but i thought it would be better to start a new one. http://www.mrexcel.com/forum/showthread.php?t=83164
Also, if there's a way to do this with cell selections instead of input boxes that would be awesome.
Thanks in advance for any help!
</day(a1)),-1)))&"></month(a1),and(month(a2)=month(a1),>
=YEAR(A2)-YEAR(A1)-IF(OR(MONTH(A2)<month(a1),and(month(a2)=month(a1), day(a2)<day(a1))),1,0)&"="" years,="" "&month(a2)-month(a1)+if(and(month(a2)="" <="MONTH(A1),DAY(A2)<DAY(A1)),11,IF(AND(MONTH(A2)<MONTH(A1),DAY(A2)">=DAY(A1)),12,IF(AND(MONTH(A2)>MONTH(A1),DAY(A2)<day(a1)),-1)))&" months,="" "&a2-date(year(a2),month(a2)-if(day(a2)<day(a1),1,0),day(a1))&"="" days"<="" pre=""> Where A2 is the most recent date
and A1 is the oldest date
and will return the answer in the following format x Years, X Months, X Days
What I'm trying to do is have this as a macro with input boxes and a MsgBox rather than have the actual calculations being done in the worksheet. Unfortunately I'm still very noob with VBA and am not sure how to go about this, or if it's even possible.
I assume I can just have the value of the input boxes added to cells on the spreadsheet, calculate it in the sheet and return the value of the cell as a message box but was hoping there was some way to do this without affecting the contents of the sheet.
There is an 8 year old thread on this but i thought it would be better to start a new one. http://www.mrexcel.com/forum/showthread.php?t=83164
Also, if there's a way to do this with cell selections instead of input boxes that would be awesome.
Thanks in advance for any help!
</day(a1)),-1)))&"></month(a1),and(month(a2)=month(a1),>