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

Remplacement de
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# ## ## ## ##")

par

Private Sub TextBox3_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If Len(TextBox3.Text) = 2 Or Len(TextBox3.Text) = 5 Or Len(TextBox3.Text) = 8 Or Len(TextBox3.Text) = 11 Then TextBox3.Text = TextBox3.Text & " "
End Sub

et aussi

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

marche pas...
 

Pierrot93

XLDnaute Barbatruc
Re : Mise en forme TextBox VBA

Re,

il faut ceci pour un même "textbox" :
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) = 2 Or Len(TextBox6.Text) = 5 Or Len(TextBox6.Text) = 8 Or Len(TextBox6.Text) = 11 Then TextBox6.Text = TextBox6.Text & " "
End Sub

ou alors quelque chose m'échappe dans ce que tu attends...
 

jokerfidelio

XLDnaute Occasionnel
Re : Mise en forme TextBox VBA

voila ce que j'ai entré et toujours le même souci,

lorsque je tape par exemple dans le module de recherche en haut a gauche"1762"
le résultat du numéro de fax est bien affiche dans la case qui lui correspond, mais comme ceci : 235074395 et j'aimerais que sans que j'ai besoin de cliquer sur cette fameuse case ou le résultat s'affiche qu'il y ai cette forme de résultat immédiat sans aucun clic dans cette case : 02 35 07 43 95 car ce résultat que je souhaite n'est pas automatique ! il a besoin de l'action d'un clic sur cette case pour prendre forme.

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 TextBox6 : 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)
If Len(TextBox3.Text) = 2 Or Len(TextBox3.Text) = 5 Or Len(TextBox3.Text) = 8 Or Len(TextBox3.Text) = 11 Then TextBox3.Text = TextBox3.Text & " "
End Sub
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

idem avec ceci

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) = 2 Or Len(TextBox6.Text) = 5 Or Len(TextBox6.Text) = 8 Or Len(TextBox6.Text) = 11 Then TextBox6.Text = TextBox6.Text & " "
End Sub

merci d'avance de vos reponses...
 

Discussions similaires

Réponses
8
Affichages
212

Statistiques des forums

Discussions
312 764
Messages
2 091 872
Membres
105 084
dernier inscrit
lca.pertus