‘’Conversione della data da 21012016 a 21/01/2016 Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) If Intersect(Target, Range("A1:A100")) Is Nothing Then Exit Sub On Error Resume Next Dim S_data As String Target.NumberFormat = "General" Application.EnableEvents = False Select Case Len(Target.Value) Case 4 S_data = "0" & Mid(Target.Value, 1, 1) & "0" & Mid(Target.Value, 2, 1) & "20" & _ Mid(Target.Value, 3, 2) Case 5 S_data = "0" & Mid(Target.Value, 1, 3) & "20" & Mid(Target.Value, 4, 2) Case 6 S_data = Mid(Target.Value, 1, 4) & "20" & Mid(Target.Value, 5, 2) Case 7 S_data = "0" & Target Case 8 S_data = Target.Value Case Else Cells(Target.Row, Target.Column) = "Dato Non valido" Application.EnableEvents = True Exit Sub End Select Target = DateSerial(Mid(S_data, 5, 4), Mid(S_data, 3, 2), Mid(S_data, 1, 2)) Target.NumberFormat = "dd/mm/yyyy" Application.EnableEvents = True End Sub |