Hello,
I want to write some VBA that does the following:
user enters an integer into a cell
store the integer
change the cell value to '=today()-integer'
I have pretty much got everything I need written, the problem is, I am using Target.Value, which is showing the integer converted into date format. I.e: 5 becomes 04/01/1900, 100 becomes 09/04/1900 etc.
Here is my code:
I want to write some VBA that does the following:
user enters an integer into a cell
store the integer
change the cell value to '=today()-integer'
I have pretty much got everything I need written, the problem is, I am using Target.Value, which is showing the integer converted into date format. I.e: 5 becomes 04/01/1900, 100 becomes 09/04/1900 etc.
Here is my code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' Cells
Set KeyCells = Range("B4:F9")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
' Code here
If IsNumeric(Target.Value) Then
Range(Target.Address).Select
ActiveCell.FormulaR1C1 = "=today()-" & Target.Value
End If
End If
End Sub