In order to ease the data entry, I am allowing users to enter the date as "ddmmyyyy" without "/", e.g, "12032017" . After the entry I want to update the target cell with value "dd/mm/yyyy", e.g, "12/03/2017".
At the start the format of the target cell is set to "General" but as soon as the date value is calculated, format of the cell is automatically changed to "dd/m/yyyy".
I have tried to use both the General and date format. Below is the VBA code
If Not Intersect(Target, Range("D11:D510")) Is Nothing Then
If Not (Target.Value = "") Then
Application.EnableEvents = False ' very important
Target.Value = Left(Target.Value, 2) & "/" & Mid(Target.Value, 3, 2) &
"/" & Right(Target.Value, 4)
Application.EnableEvents = True 'very important
End If
End If
12032017is not a valid recognizable date that Excel will automatically change, so simply changing the format will not work. You will need vba in a Worksheet_Change event, that parses the string and returns a date, that you then can format properly.