Hey guys, I'm trying to find out how I would compare the days in two date cells, and write this number (ie, 4) into a cell.
I've been told that I might need to use the DateDiff function, but it's all looking a bit confusing!
Cheers,
Pete
Hey guys, I'm trying to find out how I would compare the days in two date cells, and write this number (ie, 4) into a cell.
I've been told that I might need to use the DateDiff function, but it's all looking a bit confusing!
Cheers,
Pete
DateDiff is only available via VBA code
You will need to use one of these two examples
As a macro
Sub MyMacro()
Range("a1").Value = DateDiff("d", Range("b1").Value, Range("c1").Value)
End Sub
or as an Excel function which is avaiable as a normal Excel function
Function MyFunction(Date1 As Range, Date2 As Range) As Integer
MyFunction = DateDiff("d", Date1, Date2)
End Function
Once the above function code is entered into a VBA module sheet the function is available in a spreadsheet
to use in a1 type in =MyFunction(b1,c1)
in b1 & c1 enter 2 different dates
You can change the function name to any name that suits you just remember to change all entries from MyFunction to your desired name.
The "d" in the datediff means dispaly the number of days different between the dates, the result can be seconds, minutes, hours, days etc by changing the d to one of these
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
Good afternoon
There is a =DateDif() function available as a standard worksheet function. Unfortunately, it doesn't appear in the Insert > Function list, or in the help (although it was documented in the Help system of XL2000, but mysteriously never before or since – no-one’s quite sure why but legal reasons are often cited). Chip Pearson’s pages offer a nice tutorial on this mysterious function.
http://www.cpearson.com/excel/datedif.htm
HTH
DominicB
Please familiarise yourself with the rules before posting. You can find them here.
DominicB
Thanks for the info. It makes it easier than my suggestion
Thanks, both of you!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks