Goodday,
I'm struggling for a few days with a problem.
I need to input a lot of dates. I want to simplify the entries by typing 120521 in the cell and the cell gets the new value of 12/05/2021
The conversion part is done... but when I try to put the new date in the old cell... I get or errors type mismatch or loops of death. (excel crash) or nothing.
Below the code, I have so far. I put some debug.print so you can see the results.
Would appreciate some help or tips.
I'm struggling for a few days with a problem.
I need to input a lot of dates. I want to simplify the entries by typing 120521 in the cell and the cell gets the new value of 12/05/2021
The conversion part is done... but when I try to put the new date in the old cell... I get or errors type mismatch or loops of death. (excel crash) or nothing.
Below the code, I have so far. I put some debug.print so you can see the results.
Would appreciate some help or tips.
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Dim rawdate As String
Dim newdate As String
Dim printdate As String
If Target.Value <> "" Then
Debug.Print Target.Value
rawdate = Target.Value
Debug.Print rawdate
If Len(rawdate) = 6 Then
newdate = Left(rawdate, 2) & "/" & Mid(rawdate, 3, 2) & "/20" & Right(rawdate, 2)
Debug.Print newdate
Else
newdate = "0" & Left(rawdate, 1) & "/" & Mid(rawdate, 2, 2) & "/20" & Right(rawdate, 2)
Debug.Print newdate
End If
Debug.Print Target.Address
End If