Adding string text after the result of .Formula function

KarimK9

New Member
Joined
Feb 16, 2020
Messages
7
Office Version
  1. 365
Platform
  1. Windows
In my code, I am letting the user insert a desired date. I then use today's date and the user's input date to calculate the number of days that have passed since the input date & update it daily. This is the code.

Target.NumberFormat = "0"
Target.Formula = "=Today()- " & CLng(Target)

However, I am trying to add "Day/s Ago" after the formula output but it doesn't work (Ex: 4 Day/s Ago).
Tried to use & "Day/s Ago" after the formula but it didn't work.
Any clue how can I get it working?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
This should work for you
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target = Empty Then Exit Sub
  If Target.CountLarge > 1 Then Exit Sub

  On Error Resume Next
  Target.Formula = "=DATEDIF(" & Target.Formula & ",TODAY(),""d"") & "" Days Ago"""
  On Error GoTo 0
End Sub
 
Upvote 0
This should work for you
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target = Empty Then Exit Sub
  If Target.CountLarge > 1 Then Exit Sub

  On Error Resume Next
  Target.Formula = "=DATEDIF(" & Target.Formula & ",TODAY(),""d"") & "" Days Ago"""
  On Error GoTo 0
End Sub

It actually worked, thank you so much mate!
 
Upvote 0

Forum statistics

Threads
1,214,619
Messages
6,120,550
Members
448,970
Latest member
kennimack

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