Prevost
Board Regular
- Joined
- Jan 23, 2014
- Messages
- 198
Hi There,
I need to calculate the difference between two dates (in days) using VBA. I want the date to be put into the active cell and the start date and end date are referenced from that active cell. I think that my variables are not declared correctly or I need to convert the activecell.offset values into some variable so that VBA knows what to do with it. There was actually the same post (unfortunately with no answer) at []vba - Excel 2010 - Using ActiveCell.Offset to set variables for use in DateDiff macro - Stack Overflow so I thought I would try my luck with MrExcel. My date cells are in the form mm/dd/yyyy. Thanks in advance.
Windows 7 & Excel 2007
I need to calculate the difference between two dates (in days) using VBA. I want the date to be put into the active cell and the start date and end date are referenced from that active cell. I think that my variables are not declared correctly or I need to convert the activecell.offset values into some variable so that VBA knows what to do with it. There was actually the same post (unfortunately with no answer) at []vba - Excel 2010 - Using ActiveCell.Offset to set variables for use in DateDiff macro - Stack Overflow so I thought I would try my luck with MrExcel. My date cells are in the form mm/dd/yyyy. Thanks in advance.
Windows 7 & Excel 2007
Code:
<code>Dim date1 As Date Dim date2 As Date date1 = ActiveCell.Offset(-3, 0).Value date2 = ActiveCell.Offset(-1, 0).Value ActiveCell.Value = DATEDIFF("d", date1, date2)</code></pre>