Convert past date into number of weeks/months ago

Ironman

Well-known Member
Joined
Jan 31, 2004
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
The last row in Column A contains a date.

I need the value in Column A to be expressed in A8 as "Last walk X days/weeks/months ago" as follows:

If X is less than 7 days then it's "Last walk X days ago"
If X is equal to 7 days then it's "Last walk 1 week ago"
If X is less than 1 month then it's "Last walk X weeks ago" (the number of complete weeks)
If X is equal to 1 month then it's "Last walk 1 month ago"
If X is greater than 1 month and less than 2 months then it's "Last walk X weeks ago"
If X is equal or greater than 2 months then it's "Last walk X months ago" (the number of complete months)

Many thanks!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
So what if the last date is in a cell already past A8 ??
Also, is that a 28 day month, 30 day month OR 31 day
I can see a whole lot of issues getting the right result based on the criteria !
 
Upvote 0
OK, just to say first of all that this would be triggered by a worksheet_change event.

If I've understood you correctly

1. A8 value will always change, as it's dependant on the date in the last row (say A100). So if A100 is August 9 2021 then today A8 will return "Last walk 1 month ago" and on Oct 9 if no newer entries it will be "Last walk 2 months ago" but if I go for a walk tomorrow then in 3 days' time it will be "Last walk 2 days ago".

2. Good question and it's not important to me - say 28 days if that makes it easier for you?

Thanks again!
 
Upvote 0
So this needs to be coded or a Fairly long formula ???
With only 3 criteria we are up to.......
Excel Formula:
=IF(TODAY()-A6<7,"Last walk "&TODAY()-A6&" days ago",IF(TODAY()-A6=7,"Last walk 1 week ago",IF(TODAY()-A6<31,"Last walk "&INT(DATEDIF(A6,TODAY(),"d")/7)&" weeks ago",IF(TODAY()-A6=31,"Last walk "&INT(DATEDIF(A6,TODAY(),"m"))&" month ago"))))
 
Upvote 0
Ahhhh! Thanks Michael!

Coding is fine if it's easier for you than that clunkiness ;)
 
Upvote 0
Yeah I may not get to it today, so if someone else doesn't jump in, I'll get to it later !!
 
Upvote 0
Try this...it goes in the sheet module NOT thisworkbook module
VBA Code:
Private Sub worksheet_change(ByVal target As Range)
Dim lr As Long, mv As Integer
lr = Cells(Rows.Count, "A").End(xlUp).Row
If Intersect(target, Range("A" & lr)) Is Nothing Then Exit Sub
If target.Count > 1 Then Exit Sub
mv = Date - Cells(lr, 1).Value
Select Case mv
    Case Is < 7
        Cells(8, 1).Value = "Last walk " & mv & " days ago"
    Case Is = 7
        Cells(8, 1).Value = "Last walk 1 week ago"
    Case Is < 28
        Cells(8, 1).Value = "Last walk " & Int(mv / 7) & " weeks ago"
    Case Is = 28
        Cells(8, 1).Value = "Last walk 1 Month ago"
    Case Is < 56
        Cells(8, 1).Value = "Last walk " & Int(mv / 7) & " weeks ago"
    Case Is >= 56
        Cells(8, 1).Value = "Last walk " & Int(mv / 28) & " Months ago"
    Case Is < 0
        Cells(8, 1).Value = "Stop playing with VBA and go for a walk"
    End Select

End Sub
 
Upvote 0
Solution
Haha, I saw what you did, that's brilliant Michael, works perfectly, thanks a lot :)
 
Upvote 0

Forum statistics

Threads
1,215,098
Messages
6,123,082
Members
449,094
Latest member
mystic19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top