Imposer un caratere avant le texte

camadian

XLDnaute Junior
:confused:
Bonjour,
un peu néophyte avec VBA
je souhaiterai que lors de ma saisie via un masque
que le 1er caractère soit un "-" puis 4 chiffres ou lettres
voila mon script mais un gros bug

Private Sub TextBoxLiasse_Change()
Dim FormatLiasse As String
FormatLiasse = "-"
TextBoxVersion = Format(FormatLiasse & TextBoxLiasse)
If Len(FormatLiasse & TextBoxLiasse) > 5 Then
TextBoxLiasse = Left(FormatLiasse & TextBoxLiasse, 5)
End If

format souhaité "-1234"
Merci pour votre aide
 

GBI

XLDnaute Occasionnel
Re : Imposer un caratere avant le texte

:confused:
Bonjour,
un peu néophyte avec VBA
je souhaiterai que lors de ma saisie via un masque
que le 1er caractère soit un "-" puis 4 chiffres ou lettres
voila mon script mais un gros bug

Private Sub TextBoxLiasse_Change()
Dim FormatLiasse As String
FormatLiasse = "-"
TextBoxVersion = Format(FormatLiasse & TextBoxLiasse)
If Len(FormatLiasse & TextBoxLiasse) > 5 Then
TextBoxLiasse = Left(FormatLiasse & TextBoxLiasse, 5)
End If

format souhaité "-1234"
Merci pour votre aide
Bonjour Camadian
Essaies avec ca:
Code:
Private Sub TextBoxLiasse_Change()
Dim FormatLiasse As String
FormatLiasse = "[COLOR="Red"]'[/COLOR]-"
TextBoxVersion = Format(FormatLiasse & TextBoxLiasse)
If Len(FormatLiasse & TextBoxLiasse) > 5 Then
    TextBoxLiasse = Left(FormatLiasse & TextBoxLiasse, 5)
End If
 

pierrejean

XLDnaute Barbatruc
Re : Imposer un caratere avant le texte

bonjour camadian

Salut GBI

A tester:

Code:
Private Sub TextBox1_Change()
If Len(TextBox1) < 5 Then
 If Left(TextBox1, 1) <> "-" Then
   TextBox1 = "-" & TextBox1
 End If
Else
SendKeys "{ENTER}"
End If
End Sub
 

Statistiques des forums

Discussions
312 323
Messages
2 087 297
Membres
103 511
dernier inscrit
mickael.das