VBA forcer affichage nombre sous format "0,00"

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

  • XDL FN-CCA.xlsm
    207.3 KB · Affichages: 53
Dernière édition:

Discussions similaires

Réponses
3
Affichages
2 K

Membres actuellement en ligne

Aucun membre en ligne actuellement.

Statistiques des forums

Discussions
312 206
Messages
2 086 219
Membres
103 158
dernier inscrit
laufin