VBA forcer affichage nombre sous format "0,00"

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

max.lander

XLDnaute Occasionnel
Bonjour à tous,

J'ai un peux de mal avec le code VBA dans le fichier joint.

Le code en PJ génère un fichier texte (à la racine de D🙂 avec un certain nombre de données et notamment des montant que je souhaite impérativement afficher sous format "0,00" or le système est très aléatoire


Cela fonctionne bien pour certaines cellules pour d'autres je peux avoir par exemple

600 au lieu de 600,00
50,4 au lieu de 50,40
etc...

Il y a deux procédures "processing" qui génère les lignes (I,II, III) et la routine CCA qui les reprend les données pour les inscrire dans le fichier txt.


Je ne comprends d' où vient le problème !


Il s'agit "Format(Cells(cell.Row, (cell.Column) + 16).Value, "0.00")" de dans ligne I et des variables Montant et Montant_Total




VB:
Dim LineI, LineII, LineIII, Chemin, tableau() As String

Dim t, derligne As Integer
Dim Montant_Total, Montant As Variant ' à corriger bloque certaine fois sur Montant quand déclaration variable avec Double


Public Sub processing()

Chemin = "D:\CCA" & " " & Format(Now, "ddmmyyyy  hh.mm.ss") & ".txt"

Dim CCA_FNP As Double

derligne = Range("A" & Rows.Count).End(xlUp).Row

For i = 1 To derligne

A = "C" & i

CCA_FNP = Format(Application.WorksheetFunction _
.SumIf(Range("A1:A" & derligne), A, Range("Q1:Q" & derligne)), "0.00")

If CCA_FNP > 0 Then


          t = 0
    
         For Each cell In Range("A1:A" & derligne)
    Montant_Contrat = CCA_FNP

                        
                              If cell.Value = A Then
                        
                 Général = cell.Value
       
             t = t + 1
            ReDim Preserve tableau(t)
      
       
libellé = "CCA/CONTRAT " & Cells(cell.Row, (cell.Column) + 2).Value & " au " & Date_Clôture
Compte = Cells(cell.Row, (cell.Column) + 8).Value


Montant = Format(Cells(cell.Row, (cell.Column) + 16).Value, "0.00")
§ = ";"

Journal = "CLO"
Opération = "ODG"
Sens = "C"
Sens_total = "D"
Tpe_Anal = "A"
Analytique = Cells(cell.Row, (cell.Column) + 15).Value

Compte_Total = "4860000"
Réf = Cells(cell.Row, (cell.Column)).Value & "-" & Date_Clôture


LineI = Journal & § & Opération & § & Date_Clôture & § & Compte & § & Tpe_Anal & § & § & Format(Cells(cell.Row, (cell.Column) + 16).Value, "0.00") & § & Sens & § & libellé & § & Réf & § & Analytique & § & § & § & § & § & §

tableau(t) = LineI

     End If
                   Next cell


End If

If Général = A Then

LineII = Journal & § & Opération & § & Date_Clôture & § & Compte & § & § & § & Montant_Contrat & § & Sens & § & libellé & § & Réf & § & § & § & § & § & § & §

LineIII = Journal & § & Opération & § & Date_Clôture & § & Compte_Total & § & § & § & Montant_Contrat & § & Sens_total & § & libellé & § & § & § & Date_Clôture & § & § & § & § & §



Call CCA

End If

Next i


End Sub


' Deuxième procédure




Sub CCA()


Nom_fichier = Chemin

Dim intFic As Integer
intFic = FreeFile

Open Nom_fichier For Append As intFic

Print #intFic, LineII

For t = 1 To UBound(tableau)

Print #intFic, tableau(t)

Next t


Print #intFic, LineIII

Close intFic

End Sub
 

Pièces jointes

Dernière édition:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Microsoft 365 worksheet_change
Réponses
29
Affichages
246
Réponses
3
Affichages
233
Réponses
2
Affichages
400
Réponses
3
Affichages
462
Réponses
33
Affichages
3 K
Retour