Thread
:
excel vba number of days expressed in weeks and days
View Single Post
#
2
Posted to microsoft.public.excel.programming
Claus Busch
external usenet poster
Posts: 3,872
excel vba number of days expressed in weeks and days
Hi,
Am Tue, 2 Oct 2018 18:20:01 -0700 (PDT) schrieb
:
The output of this line of code:
in " & (dEventDate - dEmailDate) & " days"
would be:
"in 36 days".
How can I get it to read " in 5 weeks and 1 day"?
try:
Dim myWeek As Integer, myDay As Integer
Dim sWeek As String, sDay As String
Dim Output As String
myWeek = (dEventDate - dEmailDate) \ 7
myDay = (dEventDate - dEmailDate) Mod 7
sWeek = IIf(myWeek = 1, "week", "weeks")
sDay = IIf(myDay = 1, "day", "days")
If myWeek = 0 Then
Output = "in " & myDay & " " & sDay
ElseIf myDay = 0 Then
Output = "in " & myWeek & " " & sWeek
Else
Output = "in " & myWeek & " " & sWeek & " and " & myDay & " " & sDay
End If
Regards
Claus B.
--
Windows10
Office 2016
Reply With Quote
Claus Busch
View Public Profile
Find all posts by Claus Busch