Microsoft 365 Décimales Listbox

Marvin57

XLDnaute Occasionnel
Bonjour le forum,

je m'adresse à vous pour vous demander de l'aide.

J'ai un UserForm qui contient un Listbox (Listbox10) et il y a deux colonnes dans lesquelles je n'arrive pas à obtenir les décimales si elles sont ,00.

Donc par exemple, si j'ai un prix de 1 € qui me multiplie une quantité de 10 il devrait m'afficher 10,00 €. Or, il n'affiche que 10

Ce Listbox à comme source l'onglet "CAVE" et la colonne "G" de l'onglet contient le prix unitaire. La colonne "H" contient la valeur du stock du produit.


Voici un exemple de code que j'ai essayé mais la aussi, sans résultat.

Private Sub UserForm_Initialize()
Dim I%, X As Integer
X = 0

For X = 0 To Me.ListBox10.ListCount - 1
With Me.ListBox10
.List(X, 6) = Format(Sheets("CAVE").Range("G"), "##,##0.00 €")
.List(X, 7) = Format(Sheets("CAVE").Range("H"), "##,##0.00 €")
End With
Next X




Pourriez-vous me guider SVP.

Merci et à +

Marvin57
 
Solution
Il suffit de compléter la macro :
VB:
Sub InitListBox()
Dim tblBD, i&
tblBD = [Tab_1]
For i = 1 To UBound(tblBD)
    tblBD(i, 7) = Format(tblBD(i, 7), "#,##0.00 €")
    tblBD(i, 8) = Format(tblBD(i, 8), "#,##0.00 €")
Next
ListBox10.List = tblBD
ListBox10.ColumnCount = 10
ListBox10.ColumnWidths = "50;100;280;50;50;50;50;50;80;20"
End Sub

Phil69970

XLDnaute Barbatruc
Bonjour @Marvin57

Un essai

VB:
Private Sub UserForm_Initialize()
Dim I%, X As Integer
X = 0

For X = 0 To Me.ListBox10.ListCount - 1
    With Me.ListBox10
        .List(X, 6) = Sheets("CAVE").Range("G").Text
        .List(X, 7) = Sheets("CAVE").Range("H").Text
    End With
Next X

Si cela ne convient pas merci de mettre un fichier.....

Merci de ton retour

@Phil69970
 
Dernière édition:

Marvin57

XLDnaute Occasionnel
Bonjour @Marvin57

Un essai

VB:
Private Sub UserForm_Initialize()
Dim I%, X As Integer
X = 0

For X = 0 To Me.ListBox10.ListCount - 1
    With Me.ListBox10
        .List(X, 6) = Sheets("CAVE").Range("G").Text
        .List(X, 7) = Sheets("CAVE").Range("H").Text
    End With
Next X

Si cela ne convient pas merci de mettre un fichier.....

Merci de ton retour

@Phil69970
Bonjour Phil69970,

Merci pour votre réponse, malheureusement cela ne change rien.

Pour le fichier, c'est trop compliqué il est immense et trop de données confidentielles.
Dommage qu'on ne pense pas à faire un fichier vierge lors de nos créations !

Merci encore mais je vais faire des essais et voir si cela change ou pas.

Cdlt Marvin57
 

Marvin57

XLDnaute Occasionnel
Bonjour,

Si la ListBox est chargée par sa propriété RowSource les formats de la plage source sont copiés.

A+
Bonjour job75

Merci pour votre retour. Alors voici les codes tels qu'ils sont dans le UserForm, si cela peut aider.

Le tableau Tab_1 est la base de données pour le listbox.


Private Sub ListBox10_Click()
Dim ligne As Long, Nbre As Integer, I As Byte


Set result = [Tab_1[ID]].Find(ListBox10, LookIn:=xlValues, lookat:=xlWhole)
position = result.Row - [Tab_1].Row + 1
ComboBox10 = [Tab_1].Item(position, 2)
Me.lblID.Caption = [Tab_1].Item(position, 1)
For I = 1 To 3
Controls("TextBox" & I) = [Tab_1].Item(position, I + 2)
Next I
TextBox4 = [Tab_1].Item(position, 6)
TextBox5 = Format([Tab_1].Item(position, 7), "0.00 €")
TextBox6 = [Tab_1].Item(position, 9)
TextBox10 = [Tab_1].Item(position, 10)
ComboBox2 = [Tab_1].Item(position, 4)
TextBox21 = [Tab_1].Item(position, 4)

End Sub



Private Sub UserForm_Initialize()
Dim I%

TextBox11.Value = Sheets("TDB STOCK").Range("F6").Value
TextBox13.Value = Sheets("TDB STOCK").Range("C15").Value
TextBox14.Value = Sheets("TDB STOCK").Range("C17").Value
TextBox15.Value = Sheets("TDB STOCK").Range("C19").Value
TextBox24.Value = Sheets("TRIER STOCK").Range("M2").Value

TextBox24 = Format(TextBox24, "#,##0.00 €")

TextBox16.Value = Sheets("TDB STOCK").Range("C12").Value
TextBox17.Value = Sheets("TDB STOCK").Range("B12").Value
TextBox18.Value = Sheets("CDE").Range("K1").Value
TextBox22.Value = Sheets("CDE").Range("O1").Value
TextBox23.Value = Sheets("CDE").Range("R1").Value

With [Tab_1[Rayons]]
For I = 1 To .Rows.Count
ComboBox10 = .Item(I, 1)
'...et filtre les doublons
If ComboBox10.ListIndex = -1 Then ComboBox10.AddItem .Item(I, 1)
Next I
End With

ComboBox10.ListIndex = -1

Nettoie
Tri_Stock
ReIndex_ID
InitListBox

'Ote la croix de l'userform - Code Option Explicit dans module MOT_DE_PASSE
OteCroix Me.Caption
End Sub



Sub InitListBox()
tblBD = [Tab_1].Value
Me.ListBox10.List = tblBD
Me.ListBox10.ColumnCount = 10
Me.ListBox10.ColumnWidths = "50;100;280;50;50;50;50;50;80;20"

End Sub

J'espère que vous pourrez m'aider.

Cdlt Marvin57
 

job75

XLDnaute Barbatruc
Il suffit de compléter la macro :
VB:
Sub InitListBox()
Dim tblBD, i&
tblBD = [Tab_1]
For i = 1 To UBound(tblBD)
    tblBD(i, 7) = Format(tblBD(i, 7), "#,##0.00 €")
    tblBD(i, 8) = Format(tblBD(i, 8), "#,##0.00 €")
Next
ListBox10.List = tblBD
ListBox10.ColumnCount = 10
ListBox10.ColumnWidths = "50;100;280;50;50;50;50;50;80;20"
End Sub
 

Marvin57

XLDnaute Occasionnel
Il suffit de compléter la macro :
VB:
Sub InitListBox()
Dim tblBD, i&
tblBD = [Tab_1]
For i = 1 To UBound(tblBD)
    tblBD(i, 7) = Format(tblBD(i, 7), "#,##0.00 €")
    tblBD(i, 8) = Format(tblBD(i, 8), "#,##0.00 €")
Next
ListBox10.List = tblBD
ListBox10.ColumnCount = 10
ListBox10.ColumnWidths = "50;100;280;50;50;50;50;50;80;20"
End Sub
Re job75,

cela fonctionne très bien. Je vous remercie beaucoup pour votre aide.

Très bonne fin de journée.

Cdlt Marvin57
 

Discussions similaires

Réponses
9
Affichages
652

Statistiques des forums

Discussions
312 207
Messages
2 086 232
Membres
103 161
dernier inscrit
Rogombe bryan