Mise en forme TextBox VBA

jokerfidelio

XLDnaute Occasionnel
Bonjour a tous,

j'ai récupéré un fichier excel sur votre site (qui est d'ailleurs formidable merci au créateur) qui permet de faire une recherche sur 4 colonnes !
mais je n'arrive pas a personnalisés 2 textbox ! ( en screen plus bas )
j'aimerais que les numeros de FAX et de TEL garde leurs "0" devant et si possible d'harmoniser le tout en separant les chiffres 2 par 2 comme il est possible sur excel !
mais avec VBA je n'arrive a rien...



ci joint fichier a modifier

merci d'avance a celui ou celle qui pourra m'aider...
 

Pièces jointes

  • RECHERCHE.xls
    656 KB · Affichages: 1 314
  • RECHERCHE.xls
    656 KB · Affichages: 1 418
  • RECHERCHE.xls
    656 KB · Affichages: 1 405

jokerfidelio

XLDnaute Occasionnel
Re : Mise en forme TextBox VBA

si j'ai bien tout compris il faut ajouter ce code :
Option Explicit

Const entrees_entieres_permises = "0123456789"

' Modifier propriété MaxLength TextBox6 : 14
Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox6.Text = Format(TextBox6.Text, "0# ## ## ## ##")
End Sub

Private Sub TextBox6_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr(entrees_entieres_permises, Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub

Private Sub TextBox6_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If Len(TextBox6.Text) = 10 Then TextBox6.Text = Format(TextBox6.Text, "0# ## ## ## ##")
End Sub

mais je ne sais pas ou mettre ces valeurs !!!
 

jokerfidelio

XLDnaute Occasionnel
Re : Mise en forme TextBox VBA

je suis désolé je débute et sans vraiment beaucoup de connaissance dans ce domaine !

voila a quoi ressemble mon code dans cette fameuse TEXTBOX3

End Sub

Private Sub TextBox2_Change()

End Sub

Private Sub TextBox3_Change()

End Sub

Private Sub TextBox4_Change()

End Sub

Private Sub TextBox7_Change()

End Sub

Private Sub TextBox8_Change()

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then Cancel = True
End Sub
Private Sub lbx1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Label1.Caption = ""
p = 0.02: s = Timer: Do While Timer < s + p: DoEvents: Loop
Label1.Caption = "1111"
End Sub
 

Pierrot93

XLDnaute Barbatruc
Re : Mise en forme TextBox VBA

Bonjour,

j'ai essayé d'inserer le code fourni entre :
Private Sub TextBox3_Change()
End Sub
et de renommer TextBox6 fourni dans l'exemple en TextBox3 partout ou se trouvé TextBox6

non, le code donné était à inséré / adapter en l'état... tu peux d'ailleurs supprimer tous ces :
Code:
Private Sub TextBox3_Change()
End Sub

puisque vides de toute instruction.....

bon après midi
@+
 

jokerfidelio

XLDnaute Occasionnel
Re : Mise en forme TextBox VBA

voici mon code en entier

Option Explicit
Option Compare Text
Dim t As Variant, ta() As String, p As Long, s As Long
Dim X As Long, i As Long, j As Long, k As Long, e As Byte
Private Sub CommandButton4_Click()
Unload Me: [a1].Select
End Sub
Private Sub CommandButton5_Click()
t = Range("a8:f" & Range("a65536").End(xlUp).Row)
Lbx1.List = t
End Sub

Private Sub Image1_Click()

End Sub

Private Sub Label1_Click()

End Sub

Private Sub Label2_Click()

End Sub

Private Sub reset_Click()
Unload Me: UserForm1.Show
End Sub
Private Sub Tbx1_Change()
On Error Resume Next
Application.ScreenUpdating = False
t = Range("a8:f" & Range("a65536").End(xlUp).Row)
Lbx1.Clear
X = 1
For i = 1 To UBound(t)
For j = 1 To 4
If Left(t(i, j), Len(Tbx1)) = Left(Tbx1, Len(Tbx1)) Then
ReDim Preserve ta(1 To 6, 1 To X)
For k = 1 To 6
ta(k, X) = t(i, k)
Next k: X = X + 1: End If: Next j: Next i
Lbx1.List = Application.Transpose(ta)
If X - 1 = 1 Then
For e = 1 To 6
Controls("Textbox" & e) = Lbx1.List(Lbx1.ListIndex + e)
Next e: Lbx1.Clear: End If
Erase t, ta
If Tbx1 = "" Then
Lbx1.Clear
For e = 1 To 6: Controls("Textbox" & e) = "": Next e: Lbx1.Clear: End If
Beep
End Sub

Private Sub TextBox1_Change()

End Sub

Private Sub TextBox2_Change()

End Sub

Private Sub TextBox3_Change()

End Sub

Private Sub TextBox4_Change()

End Sub

Private Sub TextBox7_Change()

End Sub

Private Sub TextBox8_Change()

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then Cancel = True
End Sub
Private Sub lbx1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Label1.Caption = ""
p = 0.02: s = Timer: Do While Timer < s + p: DoEvents: Loop
Label1.Caption = "1111"
End Sub

j'ai toujours un message d'erreur a l’insertion du nouveau code :

Option Explicit

Const entrees_entieres_permises = "0123456789"

' Modifier propriété MaxLength TextBox6 : 14
Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox6.Text = Format(TextBox6.Text, "0# ## ## ## ##")
End Sub

Private Sub TextBox6_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr(entrees_entieres_permises, Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub

Private Sub TextBox6_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If Len(TextBox6.Text) = 10 Then TextBox6.Text = Format(TextBox6.Text, "0# ## ## ## ##")
End Sub

dans Option Explicit j'ai mis le nouveau code et même renommé TextBox6 en TextBox3 mais erreur de debogage !
 
Dernière édition:

jokerfidelio

XLDnaute Occasionnel
Re : Mise en forme TextBox VBA

alors après plusieurs essai le code est maintenant bien en place et fonctionne sauf que ! et oui il y a toujours un sauf que lol
pour que cela soit fonctionnel je dois cliquer sur une autre parti de la fenêtre pour que les changements prennent effets !!! sinon la disposition des chiffres reste la même !

et deuxième question j'aimerais mettre en place le même code pour TextBox4 !!! dois je mettre en plus les memes ligne de code pour cette fois ci TextBox4 ou faut il modifier autre chose ?


Option Explicit
Option Compare Text
Dim t As Variant, ta() As String, p As Long, s As Long
Dim X As Long, i As Long, j As Long, k As Long, e As Byte
Const entrees_entieres_permises = "0123456789"

' Modifier propriété MaxLength TextBox3 : 14
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox3.Text = Format(TextBox3.Text, "0# ## ## ## ##")
End Sub

Private Sub TextBox3_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr(entrees_entieres_permises, Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub

Private Sub TextBox3_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
End Sub
If Len(TextBox3.Text) = 10 Then TextBox3.Text = Format(TextBox3.Text, "0# ## ## ## ##")

Private Sub CommandButton4_Click()
Unload Me: [a1].Select
End Sub
Private Sub CommandButton5_Click()
t = Range("a8:f" & Range("a65536").End(xlUp).Row)
Lbx1.List = t
End Sub


Private Sub Image1_Click()

End Sub

Private Sub Label1_Click()

End Sub

Private Sub Label2_Click()

End Sub

Private Sub reset_Click()
Unload Me: UserForm1.Show
End Sub
Private Sub Tbx1_Change()
On Error Resume Next
Application.ScreenUpdating = False
t = Range("a8:f" & Range("a65536").End(xlUp).Row)
Lbx1.Clear
X = 1
For i = 1 To UBound(t)
For j = 1 To 4
If Left(t(i, j), Len(Tbx1)) = Left(Tbx1, Len(Tbx1)) Then
ReDim Preserve ta(1 To 6, 1 To X)
For k = 1 To 6
ta(k, X) = t(i, k)
Next k: X = X + 1: End If: Next j: Next i
Lbx1.List = Application.Transpose(ta)
If X - 1 = 1 Then
For e = 1 To 6
Controls("Textbox" & e) = Lbx1.List(Lbx1.ListIndex + e)
Next e: Lbx1.Clear: End If
Erase t, ta
If Tbx1 = "" Then
Lbx1.Clear
For e = 1 To 6: Controls("Textbox" & e) = "": Next e: Lbx1.Clear: End If
Beep
End Sub

Private Sub TextBox1_Change()

End Sub

Private Sub TextBox2_Change()

End Sub

Private Sub TextBox3_Change()

End Sub

Private Sub TextBox4_Change()

End Sub

Private Sub TextBox7_Change()

End Sub

Private Sub TextBox8_Change()

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then Cancel = True
End Sub
Private Sub lbx1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Label1.Caption = ""
p = 0.02: s = Timer: Do While Timer < s + p: DoEvents: Loop
Label1.Caption = "1111"
End Sub
 

jokerfidelio

XLDnaute Occasionnel
Re : Mise en forme TextBox VBA

Re,

oui, mêmes codes pour "textbox4" sauf cette ligne :
Code:
Const entrees_entieres_permises = "0123456789"

j'avais anticipé, et cela fonctionne, mais toujours le problème de double clic sur une autre zone de la fenêtre pour mettre en place ces lignes de code dans les deux TextBox3 et TextBox4

et encore merci pour ton aide
 

Pierrot93

XLDnaute Barbatruc
Re : Mise en forme TextBox VBA

Re,

modifie peut être l'événement "KeyUp" comme suit :
Code:
Private Sub TextBox6_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If Len(TextBox6.Text) = 2 Or Len(TextBox6.Text) = 5 Or Len(TextBox6.Text) = 8 Or Len(TextBox6.Text) = 11 Then TextBox6.Text = TextBox6.Text & " "
End Sub
 

Discussions similaires

Membres actuellement en ligne

Statistiques des forums

Discussions
312 493
Messages
2 088 956
Membres
103 990
dernier inscrit
lamiadebz