ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   excel vba number of days expressed in weeks and days (https://www.excelbanter.com/excel-programming/454169-excel-vba-number-days-expressed-weeks-days.html)

[email protected]

excel vba number of days expressed in weeks and days
 
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"?


Claus Busch

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


All times are GMT +1. The time now is 06:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com