It would actually quicker to keep the formula in the worksheet. And if you keep the formula handy (in a text file or sample workbook or just a link to Chip's site), it wouldn't be too hard to copy it into your worksheet. But if you want...
Code:
Option Explicit
Function YrsMthsDays(rng1 As Range, rng2 As Range) As Variant
Dim iCtr As Long
Dim myVals(0 To 2) As Long
Dim myIntervals As Variant
Dim myStrs As Variant
Dim myOutput As String
myIntervals = Array("y", "ym", "md")
myStrs = Array(" years, ", " months, ", " days")
myOutput = ""
For iCtr = LBound(myVals) To UBound(myVals)
myVals(iCtr) = Application.Evaluate("datedif(" _
& rng1.Address(external:=True) _
& "," & rng2.Address(external:=True) _
& ",""" & myIntervals(iCtr) & """)")
myOutput = myOutput & myVals(iCtr) & myStrs(iCtr)
Next iCtr
YrsMthsDays = myOutput
End Function
Bookmarks