Microsoft 365 Concaténation et mise en forme de données

Fab117

XLDnaute Impliqué
Bonjour,

J'ai plusieurs colonnes avec un grand nombre de données (des chiffres décimaux pour la plupart).

Pour chaque colonne, je souhaite concaténer le contenu de plusieurs lignes et les mettre en forme.

Avec le code ci-dessous, j'arrive à faire la concaténation :

VB:
Sub FormatageDonneesQuiFonctionnePartiellement()
    
    Dim Source As Worksheet
    Dim Cible As Worksheet
    
    Set Source = ThisWorkbook.Sheets("Source") ' Remplacez "Source" par le nom de votre onglet source
    Set Cible = ThisWorkbook.Sheets("Cible") ' Remplacez "Cible" par le nom de votre onglet cible


    ' Formatage des données
    For col = 2 To 22 ' Boucle sur les colonnes B à V
        Cible.Cells(1, col) = Source.Cells(1, col) ' Copie de l'en-tête de colonne

        Cible.Cells(2, col) = "   " & Source.Cells(16, col) & " € | (" & (Source.Cells(16, col) / Source.Cells(23, col)) & ")" & vbNewLine & _
            "   " & Source.Cells(17, col) & " € | (" & (Source.Cells(17, col) / Source.Cells(23, col)) & ")" & vbNewLine & _
            "   " & Source.Cells(18, col) & " € | (" & (Source.Cells(18, col) / Source.Cells(23, col)) & ")" & vbNewLine & _
            "   " & Source.Cells(19, col) & " € | (" & (Source.Cells(19, col) / Source.Cells(23, col)) & ")" & vbNewLine & _
            "   " & Source.Cells(20, col) & " € | (" & (Source.Cells(120, col) / Source.Cells(23, col)) & ")" & vbNewLine & _
            "   " & Source.Cells(21, col) & " € | (" & (Source.Cells(21, col) / Source.Cells(23, col)) & ")" & vbNewLine & _
            "   " & Source.Cells(22, col) & " € | (" & (Source.Cells(22, col) / Source.Cells(23, col)) & ")" & vbNewLine & _
            (Source.Cells(23, col)) & vbNewLine

    Next col

End Sub



Mais je ne sais pas comment faire la mise en forme.

Par exemple, pour la ligne :

Code:
" " & Source.Cells(17, col) & " € | (" & (Source.Cells(17, col) / Source.Cells(23, col)) & ")" & vbNewLine & _
Pour l'instant, il m'affiche

" 9.485 € | (0.27865412358952545)"

Ce que j'attends, c'est

" 9.49 € | (27.9 %)"

=> 2 décimales pour "Source.Cells(17, col)"

=> pourcentage a une décimale pour le calcul "(Source.Cells(17, col) / Source.Cells(23, col)"



Quelqu'un saurtait-il comment adapter mon code ?



Bonne soirée.



Fab



qu'il affiche le chiffre "Source.Cells(17, col)" avec 2 décimales
 

Discussions similaires

Statistiques des forums

Discussions
312 209
Messages
2 086 270
Membres
103 168
dernier inscrit
isidore33