Mettre la colonne d'une ListBox au format 0.00€

Bonjour à tous,

J'aimerais mettre la colonne des prix de ma ListBox au format 0.00€

Voici le code que j'ai entré mais cela ne fonctionne pas:

Sub Workbook_open()
UserForm1.Show
With ListBox1
For i = 0 To ListCount - 1
.List(i, 8) = Format(.List(i, 8), "0.00€")
Next i
End With
End Sub

Merci d'avance de votre retour

Bonjour

Tu formates ta colonne au format>>>format de cellule>>comptabilité>>>

nombre de décimales 2 sigle tu choisis l'euro

Cordialement

Bonjour Joco,

Ceci est déjà fait dans mes différentes feuilles.

Une autre solution?

Cordialement.

Bonjour
A tester

Sub Workbook_open()
UserForm1.Show
With ListBox1
For i = 0 To ListCount - 1
.List(i, 8) = Format (Range(.List(i, 8).Value, "0.00€"))
Next i
End With
End Sub

Bonjour,

D'où proviennent les données chargées dans la ListBox ? C'est au moment de son initialisation qu'il faudrait modifier le format.

Joco,

Je viens de tester ta solution elle ne marche pas.

Pedro22,

J' ai essayé avec le code :

Private Sub UserForm_Initialize()
With ListBox1
For i = 0 To ListCount - 1
.List(i, 8) = Format(Range(.List(i, 8).Value, "0.00€"))
Next i
End With
End Sub

Cela ne fonctionne pas non plus. L'UserForm fonctionne de la façon suivant. On coche un CheckBox pas Frame et en fonction du nombre de choix fait, il me sort la liste présente dans la feuille "Filtrage". Voici une parti du codage:

Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
CheckBox5.Value = False
Sheets("Filtrage").Select
Range("B2").Value = "Plein"
End If
If CheckBox1.Value = False Then
Sheets("Filtrage").Select
Range("B2").Value = ""
End If
If Range("AF4").Value = "0" Then
With ListBox1
ListBox1.List = Sheets("Filtrage").Range("Y6:AF273").Value
For i = ListBox1.ListCount - 1 To 0 Step -1
    If ListBox1.List(i) = "" Then ListBox1.RemoveItem (i)
Next i
End With
End If
If Range("AF4").Value = "1" Then
With ListBox1
ListBox1.List = Sheets("Filtrage").Range("Y6:AF273").Value
For i = ListBox1.ListCount - 1 To 0 Step -1
    If ListBox1.List(i) = "" Then ListBox1.RemoveItem (i)
Next i
End With
End If
If Range("AN4").Value = "2" Then
With ListBox1
ListBox1.List = Sheets("Filtrage").Range("AG6: AN273 ").Value
For i = ListBox1.ListCount - 1 To 0 Step -1
    If ListBox1.List(i) = "" Then ListBox1.RemoveItem (i)
Next i
End With
End If
If Range("AV4").Value = "3" Then
With ListBox1
ListBox1.List = Sheets("Filtrage").Range("AO6: AV273 ").Value
For i = ListBox1.ListCount - 1 To 0 Step -1
    If ListBox1.List(i) = "" Then ListBox1.RemoveItem (i)
Next i
End With
End If
If Range("BD4").Value = "4" Then
With ListBox1
ListBox1.List = Sheets("Filtrage").Range("AW6: BD273 ").Value
For i = ListBox1.ListCount - 1 To 0 Step -1
    If ListBox1.List(i) = "" Then ListBox1.RemoveItem (i)
Next i
End With
End If
Sheets("Estimation").Select
End Sub

Voici à quoi ressemble l'UserForm:

userform

A tester :

'Remplacer la ligne :
ListBox1.List = Sheets("Filtrage").Range("Y6:AF273").Value
'Par :
ListBox1.List = Sheets("Filtrage").Range("Y6:AF273").Text

La plage doit être au préalable au format souhaité, les autres lignes sont à modifier de la même façon.

.Value désigne les valeurs (stockées et indépendantes du format de cellule), .Text les valeurs affichées (donc dépendantes du format de cellule).

Je reviens vers vous avec une version entièrement révisé de votre code, notamment pour éviter les .Select (inutiles).

Suite (à tester) :

Private Sub CheckBox1_Click()

With Sheets("Filtrage")
    If CheckBox1.Value = True Then
        CheckBox2.Value = False
        CheckBox3.Value = False
        CheckBox4.Value = False
        CheckBox5.Value = False
        .Range("B2").Value = "Plein"
    End If
    If CheckBox1.Value = False Then .Range("B2").Value = ""
    If .Range("AF4").Value = 0 Or .Range("AF4").Value = 1 Then
        ListBox1.List = .Range("Y6:AF273").Text
        For i = ListBox1.ListCount - 1 To 0 Step -1
            If ListBox1.List(i) = "" Then ListBox1.RemoveItem (i)
        Next i
    End If
    If .Range("AN4").Value = 2 Then
        ListBox1.List = .Range("AG6:AN273").Text
        For i = ListBox1.ListCount - 1 To 0 Step -1
            If ListBox1.List(i) = "" Then ListBox1.RemoveItem (i)
        Next i
    End If
    If Range("AV4").Value = 3 Then
        ListBox1.List = .Range("AO6:AV273").Text
        For i = ListBox1.ListCount - 1 To 0 Step -1
            If ListBox1.List(i) = "" Then ListBox1.RemoveItem (i)
        Next i
    End If
    If Range("BD4").Value = 4 Then
        ListBox1.List = .Range("AW6:BD273").Text
        For i = ListBox1.ListCount - 1 To 0 Step -1
            If ListBox1.List(i) = "" Then ListBox1.RemoveItem (i)
        Next i
    End If
End With

End Sub

Notes :

- L'utilisation de With Objet n'a de sens que si on évite de répéter le nom de l'objet ensuite (Objet.PropriétéMachin devient .PropriétéMachin)
- Il est préférable d'utiliser des noms plus explicites que CheckBox1 ou ListBox1, qui ne renseignent pas la fonction de l'objet en question...

Pedro,

Cela ne fonctionne pas.

Pedro,

Cela ne fonctionne pas.

Tester des solutions à l'aveugle, ce n'est pas le plus pratique... Peux tu joindre un fichier type sur lequel on pourra travailler ?

Nouvel essai :

Private Sub CheckBox1_Click()

Dim PlageLB As Range, Cel As Range

With Sheets("Filtrage")
    If CheckBox1.Value Then
        CheckBox2.Value = False
        CheckBox3.Value = False
        CheckBox4.Value = False
        CheckBox5.Value = False
        .Range("B2") = "Plein"
    End If
    If CheckBox1 = False Then .Range("B2") = ""
    If .Range("AF4") = 0 Or .Range("AF4") = 1 Then Set PlageLB = .Range("Y6:AF273")
    If .Range("AN4") = 2 Then Set PlageLB = .Range("AG6:AN273")
    If .Range("AV4") = 3 Then Set PlageLB = .Range("AO6:AV273")
    If .Range("BD4") = 4 Then Set PlageLB = .Range("AW6:BD273")
    If Not PlageLB Is Nothing Then
        For Each Cel In PlageLB
            If Not Cel = "" Then ListBox1.AddItem = Format(Cel, "0.00 €")
        Next Cel
    End If
End With

End Sub

Voici le fichier

30test-forum.xlsm (265.33 Ko)

voir le fichier

Joco,

Ce n'est toujours pas bon.

Je me suis peut-être mal exprimé désolé.

Je veux que dans la ListBox de l'Userform, quand la liste des produits s'affiche. Le prix de revient soit sous la forme 0.00€.

Merci d'avance

Nouvel essai :

Private Sub CheckBox1_Click()

Dim PlageLB As Range, i As Integer

With Sheets("Filtrage")
    If CheckBox1.Value Then
        CheckBox2.Value = False
        CheckBox3.Value = False
        CheckBox4.Value = False
        CheckBox5.Value = False
        .Range("B2") = "Plein"
    End If
    If CheckBox1 = False Then .Range("B2") = ""
    If .Range("AF4") = 0 Or .Range("AF4") = 1 Then Set PlageLB = .Range("Y6:AF273")
    If .Range("AN4") = 2 Then Set PlageLB = .Range("AG6:AN273")
    If .Range("AV4") = 3 Then Set PlageLB = .Range("AO6:AV273")
    If .Range("BD4") = 4 Then Set PlageLB = .Range("AW6:BD273")
    If Not PlageLB Is Nothing Then
        With ListBox1
            .List = PlageLB.Value
            For i = .ListCount - 1 To 0 Step -1
                If .List(i) = "" Then
                    .RemoveItem (i)
                Else
                    .List(i, 7) = Format(.List(i, 7), "0.00 €")
                End If
            Next i
        End With
    End If
End With

End Sub

A adapter pour les autres macros.

Merci Pedro.

Votre code fonctionne à merveille.

Merci encore

Merci Pedro.

Votre code fonctionne à merveille.

Merci encore

Merci du retour, pense à valider le sujet !

Rechercher des sujets similaires à "mettre colonne listbox format"