Calculating total days from 2 dates

X

xswoosh

Currently, I'm stuck in calculating the total days from 2 dates.
Let say I have *Startdate in A1*, *Enddate in B1* and the *total days
in C1*, how would I write it in VBA?

I tried using the formulas in the cells like below:

eg: Start Date=15.Nov.03 ; Enddate=30.Dec.03

in Cell C1:
=Day(B1)-Day(A1)
This gives me *16.Jan.00* as the answer!!

Plz help! thx!!
 
N

nicolas.bourmault

Hi,
Cell A1 : 15.Nov.03
Cell A2 : 30.Dec.03
Cell A3 : =A2-A1. This cell must be defined as "General"
or "number" for its format cell.
NicoB.
 
P

Patrick Molloy

SUB GetDates()

Dim Date1 As Date, Date2 As Date
Dim Total as Long

Date1 = CDate(Range("A1").Value)
Date2 = CDate(Range("B1").Value)

Total = Date2 - Date1

Range("C1").Value = Total

END SUB

Alternative

SUB DateDiff()

Range("C1").Fromular1C1="=RC2-RC1"

End Sub

The first procedure calculates the diffrence and places
the result into C1
The second sub places your formula into C1


HTH
Patrick Molloy
Microsoft Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top