Bonsoir à tous

J'ai un petit souci avec le code ci-dessous, je ne comprend pourquoi quand le textbox1 est vide et que je le quitte il met renvoie le message d'erreur "incompatibilité de type" sur la ligne en rouge.

Si quelqu'un pouvait m'expliquer pourquoi ça m'arrangerait.
Pour palier a ce probleme j'ai rajouté un test sur une valeur nul sur le code tout en dessous, apparemment ça fonctionne, mais etait-ce la bonne solution?
Sinon quelle autre solution existe.

Merci


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim c As Variant
Dim h1 As Date
Application.ScreenUpdating = False
            TextBox1.Value = TimeValue(Left(Application.Text(TextBox1.Value, "00.00"), 2) _
        & ":" & Right(TextBox1.Value, 2))   
             c = TextBox1.Value
                 h1 = TextBox1.Value
       TextBox1.Value = Format(c, "hh\H mm")
 End Sub



Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim c As Variant
Dim h1 As Date
Application.ScreenUpdating = False
If TextBox1.Value <> "" Then
            TextBox1.Value = TimeValue(Left(Application.Text(TextBox1.Value, "00.00"), 2) _
        & ":" & Right(TextBox1.Value, 2))
                c = TextBox1.Value
                 h1 = TextBox1.Value
       TextBox1.Value = Format(c, "hh\H mm")
 
      End If
 End Sub