XL 2013 Format textbox

maval

XLDnaute Barbatruc
Bonjour,

Je cherche à mettre un format à mes textBox comme ceci 100 000

J'ai fait ceci TextBox = Format("# ##0")
et après ceci
VB:
Private Sub TextBox2_AfterUpdate()
On Error Resume Next
Me.TextBox2.Value = Format(Val(Replace(TextBox2, ",", ".")), "#,##0.00")

End Sub

Sa ne fonctionne toujours pas?

Merci de votre aide
 
Dernière édition:

patricktoulon

XLDnaute Barbatruc
et oui pas facile de formater un textbox
tout d'abord pour que le afterupdate fonctionne il faut qu'il y est au moins 2 control dans le userform
ensuite pour formater il faut astucer
VB:
Private Sub TextBox1_AfterUpdate()
    TextBox1 = Replace(TextBox1, ".", ",")
    tabl = Split(TextBox1.Text, ",")
    tabl(0) = Format(tabl(0), "@@@ @@@ @@@ @@@ @@@")
    TextBox1.Value = tabl(0)
    If UBound(tabl) > 0 Then
        TextBox1.Text = TextBox1 & "," & tabl(1)
    End If
    TextBox1.Text = Trim(TextBox1.Text)
End Sub
libre a toi de coder le format que tu veux "@@...."
demo3.gif
 

maval

XLDnaute Barbatruc
Salut ChTi
Voila mon code au complet mais tu me repond jamais

VB:
Private Sub CommandButton1_Click()
Unload Me
End Sub

Private Sub Label3_Click()

End Sub

Private Sub UserForm_Initialize()

    Dim Cell As Range
    With Sheets("Populations 2019")
        For Each Cell In .Range("B6:B" & .Range("B65536").End(xlUp).Row)
            Me.ComboBox1.AddItem (Cell)
        Next
    End With

End Sub


Private Sub Combobox1_Click()

Dim lign As Long

    If ComboBox1.Value <> "" Then
        
        lign = ComboBox1.ListIndex + 6
        TextBox1.Value = Range("A" & lign).Value
        TextBox2.Value = Range("C" & lign).Value
        TextBox3.Value = Range("D" & lign).Value
        TextBox4.Value = Range("E" & lign).Value
        TextBox5.Value = Range("F" & lign).Value
        TextBox6.Value = Range("G" & lign).Value
        TextBox7.Value = Range("H" & lign).Value
        TextBox8.Value = Range("I" & lign).Value
        TextBox9.Value = Range("J" & lign).Value
        TextBox10.Value = Range("K" & lign).Value
        TextBox11.Value = Range("L" & lign).Value
        TextBox12.Value = Range("M" & lign).Value
        TextBox13.Value = Range("N" & lign).Value
        TextBox14.Value = Range("O" & lign).Value
        TextBox15.Value = Range("P" & lign).Value
        TextBox16.Value = Range("Q" & lign).Value
        TextBox17.Value = Range("R" & lign).Value
        TextBox18.Value = Range("S" & lign).Value
        TextBox19.Value = Range("T" & lign).Value
    End If
    
End Sub



Private Sub format_textbox(TxtB As MSForms.TextBox)
    TxtB = Replace(TxtB, ".", ",")
    tabl = Split(TxtB.Text, ",")
    tabl(0) = Format(tabl(0), "@@@ @@@ @@@ @@@ @@@")
    TxtB.Value = tabl(0)
    If UBound(tabl) > 0 Then
        TxtB.Text = TxtB & "," & tabl(1)
    End If
    TxtB.Text = Trim(TxtB.Text)

End Sub

Private Sub TextBox2_AfterUpdate()
format_textbox TextBox2

End Sub


Private Sub TextBox3_AfterUpdate()
format_textbox TextBox3

End Sub
 

ChTi160

XLDnaute Barbatruc
Re
je suis comme beaucoup , maintenant sans fichier , je ne réponds plus ! Lol (mais je regarde )
histoire de participer(de ne pas être passe pour rien Lol)
VB:
Private Sub format_textbox(TxtB As MSForms.TextBox)
   With TxtB
       .Text = Replace(.Text, ".", ",")
       .Text = Format(CCur(.Text), "### ### ##0.00")
   End With
End Sub
pas de chiffre en Colonne B donc ?
VB:
'un truc du genre
           TextBox1.Value = Format(CCur(Replace(Cells( lign,1), ".", ",")), "### ### ##0.00")
       For i = 2 To 19 'on va sauter une Colonne (1+i)
        Controls("TextBox" & i) = Format(CCur(Replace(Cells(lign, 1 + i), ".", ",")), "### ### ##0.00")
       Next i
non testé pas de fichier
Bonne continuation
jean marie
 
Dernière édition:

job75

XLDnaute Barbatruc
Bonjour,

Pour le séparateur de milliers en VBA on utilise la virgule.

Au lieu de tabl(0) = Format(tabl(0), "@@@ @@@ @@@ @@@ @@@")

utiliser tabl(0) = Format(tabl(0), "#,##0")

et au lieu de .Text = Format(CCur(.Text), "### ### ##0.00")

utiliser .Text = Format(.Text, "#,##0.00")

A+
 
Dernière édition:

Discussions similaires

Réponses
15
Affichages
489

Membres actuellement en ligne

Statistiques des forums

Discussions
312 164
Messages
2 085 877
Membres
103 009
dernier inscrit
dede972