Place a command button on your worksheet and add the following code lines:
Dim firstDate As Date, secondDate As Date, n As IntegerExplanation: first, we declare two dates. Next, we initialize the two dates using the DateValue function. The DateDiff function has three arguments. Fill in "d" for the first argument since we want the number of days between two dates. Finally, we use a MsgBox to display the number of days between the two dates.
firstDate = DateValue("Jun 19, 2010")
secondDate = DateValue("Jul 25, 2010")
n = DateDiff("d", firstDate, secondDate)
MsgBox n
Result when you click the command button on the sheet:
Change "d" to "ww" to get the number of weeks between two dates. Place your cursor on DateDiff in the Visual Basic Editor and click F1 for help on the other interval specifiers..