globulle93
Habitué
bonjour,
mon problème je voudrais changer cette ligne pour un sum qui ferait moins pourri car le ++++ .. fait un peux nase j'ai test différent truc mais des erreurs et j'avoue que la j'ai un peux ras le bol
adyencpta.Cells(Nextrowac, 11) = CDbl(ADYEN.Cells(i, 17)) + CDbl(ADYEN.Cells(i, 18)) + CDbl(ADYEN.Cells(i, 19)) + CDbl(ADYEN.Cells(i, 20)) - CDbl(ADYEN.Cells(i, 21))
un petit coup de pouce serait super sympa.
maintenant je fais de macro pas trop deg et plutot complexe grace a vous et vos conseil.
je vous met le code global
en gros je part d'un fichier csv dans lequel je compare des éléments avec une base pour générer des écritures en fonction de critère
si vous constater aussi des choses qui pourrais être mieux je suis toujours preneur de conseils
merci
mon problème je voudrais changer cette ligne pour un sum qui ferait moins pourri car le ++++ .. fait un peux nase j'ai test différent truc mais des erreurs et j'avoue que la j'ai un peux ras le bol
adyencpta.Cells(Nextrowac, 11) = CDbl(ADYEN.Cells(i, 17)) + CDbl(ADYEN.Cells(i, 18)) + CDbl(ADYEN.Cells(i, 19)) + CDbl(ADYEN.Cells(i, 20)) - CDbl(ADYEN.Cells(i, 21))
un petit coup de pouce serait super sympa.
maintenant je fais de macro pas trop deg et plutot complexe grace a vous et vos conseil.
je vous met le code global
en gros je part d'un fichier csv dans lequel je compare des éléments avec une base pour générer des écritures en fonction de critère
si vous constater aussi des choses qui pourrais être mieux je suis toujours preneur de conseils
merci
Code:
Option Explicit
Dim ADYEN As Worksheet
Dim adyencpta As Worksheet
Dim Boutiques As Workbook
Dim mag As Worksheet
Dim numMagA As String
Dim numboutique As String
Dim j As Integer
Dim Nextrow As Integer
Dim finalrow As Integer
Dim i As Integer
Dim Nextrowac As Integer
Dim finalrowb As Integer
Sub WECHAT()
Application.ScreenUpdating = False
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 2), Array(2, 1), Array(3, 2), Array(4, 1), Array(5, 1), Array(6, 1), _
Array(7, 1), Array(8, 1), Array(9, 2), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1 _
), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array _
(20, 1), Array(21, 1), Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1), _
Array(27, 1), Array(28, 1), Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1), Array( _
33, 1), Array(34, 1), Array(35, 1), Array(36, 1), Array(37, 1)), DecimalSeparator:="." _
, TrailingMinusNumbers:=True
'création feuille2
Set adyencpta = Worksheets.Add(after:=Worksheets(1))
'renomage feuille 2
adyencpta.Name = "Comptabilisation"
' initialisation feuille
Set ADYEN = Worksheets(1)
Set adyencpta = Worksheets(2)
Set Boutiques = GetObject("G:\**************\Boutiques.xlsx")
Set mag = Boutiques.Worksheets(1)
'calcul derniere ligne fichier Boutiques
finalrowb = mag.Cells(mag.Rows.Count, 1).End(xlUp).Row
'initialisation compteur
Nextrow = 1
Nextrowac = 1
' calcul du nombre de ligne du fichier adyen
finalrow = ADYEN.Cells(Rows.Count, 1).End(xlUp).Row
For i = finalrow To 2 Step -1
If ADYEN.Cells(i, 38) = "" And ADYEN.Cells(i, 8) = "Balancetransfer" Then
Call report
ElseIf ADYEN.Cells(i, 38) = "" And ADYEN.Cells(i, 8) = "Fee" Then
Call frais
ElseIf ADYEN.Cells(i, 38) = "" And ADYEN.Cells(i, 8) = "MerchantPayout" Then
Call modepayment
ElseIf ADYEN.Cells(i, 38) = "" And ADYEN.Cells(i, 8) = "InvoiceDeduction" Then
Call frais
Else
Call compta
End If
Next i
Set adyencpta = Nothing
Set ADYEN = Nothing
Set Boutiques = Nothing
Set mag = Nothing
Application.ScreenUpdating = True
Call sauvegarde
ActiveWorkbook.Close SaveChanges:=False
Application.DisplayAlerts = False
Application.Quit
End Sub
Private Sub compta()
If ADYEN.Cells(i, 5) = "wechatpay_pos" Then
Call ecriture 'wechatcpta
ElseIf ADYEN.Cells(i, 5) = "alipay" Then
Call ecriture 'alipaycpta
ElseIf ADYEN.Cells(i, 5) = "visa" Or ADYEN.Cells(i, 5) = "mc" Or ADYEN.Cells(i, 5) = "diners" Or ADYEN.Cells(i, 5) = "discover" Or ADYEN.Cells(i, 5) = "maestro" Then
Call ecriture
ElseIf ADYEN.Cells(i, 5) = "amex" Then
Call ecriture 'alipaycpta
End If
End Sub
'*******************************************************************************************************
'* Comptabilisation des Fees par journée *
'*******************************************************************************************************
Private Sub frais()
' ligne general de frais
adyencpta.Cells(Nextrowac, 1) = "G"
Call cptafrais
Nextrowac = Nextrowac + 1
adyencpta.Cells(Nextrowac, 1) = "A"
Call cptafrais
adyencpta.Cells(Nextrowac, 15) = "F0050"
Nextrowac = Nextrowac + 1
End Sub
Private Sub cptafrais()
' numero de la societe
adyencpta.Cells(Nextrowac, 2) = Left(ADYEN.Cells(i, 2), 5)
'type ecriture
adyencpta.Cells(Nextrowac, 4) = "BQ"
'date d operation
adyencpta.Cells(Nextrowac, 5) = CDate(adyencpta.Cells(1, 5))
'date de valeur
adyencpta.Cells(Nextrowac, 6) = CDate(adyencpta.Cells(1, 5))
'compte de charge frais
adyencpta.Cells(Nextrowac, 7) = "627800"
'****************************************************************************
'* journal en fonction de la ste
'***************************************************************************
If Left(ADYEN.Cells(i, 2), 5) = "G0006" Then
adyencpta.Cells(Nextrowac, 3) = "BNP-E CB"
ElseIf Left(ADYEN.Cells(i, 2), 5) = "G0017" Then
adyencpta.Cells(Nextrowac, 3) = "SG-EUR-CARTES"
ElseIf Left(ADYEN.Cells(i, 2), 5) = "G0027" Then
adyencpta.Cells(Nextrowac, 3) = "HSBC-EUR"
End If
'***************************************************************************
' libelle frais bancaire
adyencpta.Cells(Nextrowac, 9) = "FRAIS ADYEN" & " " & CDate(Mid(ADYEN.Cells(i, 6), 1, 10))
If ADYEN.Cells(i, 15) > 0 Then
'adyencpta.Cells(Nextrowac, 11) = adyen.Cells(i, 12)
adyencpta.Cells(Nextrowac, 10) = "D"
adyencpta.Cells(Nextrowac, 11) = ADYEN.Cells(i, 15)
ElseIf ADYEN.Cells(i, 16) > 0 Then
'adyencpta.Cells(Nextrowac, 11) = adyen.Cells(i, 12)
adyencpta.Cells(Nextrowac, 10) = "C"
adyencpta.Cells(Nextrowac, 11) = ADYEN.Cells(i, 16)
End If
adyencpta.Cells(Nextrowac, 13) = CDate(Mid(ADYEN.Cells(i, 6), 1, 10))
adyencpta.Cells(Nextrowac, 14) = "CB"
End Sub
'*******************************************************************************************************
'* Comptabilisation du Balance transfer *
'*******************************************************************************************************
Private Sub report()
adyencpta.Cells(Nextrowac, 1) = "G"
adyencpta.Cells(Nextrowac, 2) = Left(ADYEN.Cells(i, 2), 5)
If Left(ADYEN.Cells(i, 2), 5) = "G0006" Then
adyencpta.Cells(Nextrowac, 7) = "5800000"
adyencpta.Cells(Nextrowac, 3) = "BNP-E CB"
ElseIf Left(ADYEN.Cells(i, 2), 5) = "G0017" Then
adyencpta.Cells(Nextrowac, 7) = "580000"
adyencpta.Cells(Nextrowac, 3) = "SG-EUR-CARTES"
ElseIf Left(ADYEN.Cells(i, 2), 5) = "G0027" Then
adyencpta.Cells(Nextrowac, 7) = "580000"
adyencpta.Cells(Nextrowac, 3) = "HSBC-EUR"
End If
If ADYEN.Cells(i, 15) > 0 Then
adyencpta.Cells(Nextrowac, 11) = ADYEN.Cells(i, 17)
adyencpta.Cells(Nextrowac, 10) = "D"
adyencpta.Cells(Nextrowac, 11) = ADYEN.Cells(i, 15)
ElseIf ADYEN.Cells(i, 16) > 0 Then
adyencpta.Cells(Nextrowac, 11) = ADYEN.Cells(i, 17)
adyencpta.Cells(Nextrowac, 10) = "C"
adyencpta.Cells(Nextrowac, 11) = ADYEN.Cells(i, 16)
End If
If adyencpta.Cells(Nextrowac, 7) = 580000 Then
adyencpta.Cells(Nextrowac, 5) = CDate(Mid(ADYEN.Cells(finalrow, 6), 1, 10))
Else
adyencpta.Cells(Nextrowac, 5) = CDate(adyencpta.Cells(1, 5))
End If
If adyencpta.Cells(Nextrowac, 7) = 580000 Then
adyencpta.Cells(Nextrowac, 6) = CDate(Mid(ADYEN.Cells(finalrow, 6), 1, 10))
Else
adyencpta.Cells(Nextrowac, 6) = CDate(adyencpta.Cells(1, 5))
End If
adyencpta.Cells(Nextrowac, 4) = "BQ"
adyencpta.Cells(Nextrowac, 9) = "REPORT ADYEN"
adyencpta.Cells(Nextrowac, 14) = "CB"
adyencpta.Cells(Nextrowac, 13) = CDate(Mid(ADYEN.Cells(i, 6), 1, 10))
Nextrowac = Nextrowac + 1
End Sub
'*******************************************************************************************************
'* Comptabilisation écriture banque paiement *
'*******************************************************************************************************
Private Sub modepayment()
' type ecriture
adyencpta.Cells(Nextrowac, 1) = "G"
' numero de la societe
adyencpta.Cells(Nextrowac, 2) = Left(ADYEN.Cells(i, 2), 5)
Call comptecpta
adyencpta.Cells(Nextrowac, 4) = "BQ"
' date operation
adyencpta.Cells(Nextrowac, 5) = CDate(Mid(ADYEN.Cells(i, 6), 1, 10))
' date de valeur
adyencpta.Cells(Nextrowac, 6) = CDate(Mid(ADYEN.Cells(i, 6), 1, 10))
' libelle ecriture
adyencpta.Cells(Nextrowac, 9) = "VIRT ADYEN"
'*******************************************************
'* sens ecriture et montant *
If ADYEN.Cells(i, 15) > 0 Then
adyencpta.Cells(Nextrowac, 11) = ADYEN.Cells(i, 17)
adyencpta.Cells(Nextrowac, 10) = "D"
adyencpta.Cells(Nextrowac, 11) = ADYEN.Cells(i, 15)
ElseIf ADYEN.Cells(i, 16) > 0 Then
adyencpta.Cells(Nextrowac, 11) = ADYEN.Cells(i, 17)
adyencpta.Cells(Nextrowac, 10) = "C"
adyencpta.Cells(Nextrowac, 11) = ADYEN.Cells(i, 16)
End If
'********************************************************
' date d echeance
adyencpta.Cells(Nextrowac, 13) = CDate(Mid(ADYEN.Cells(i, 6), 1, 10))
' mode de reglement
adyencpta.Cells(Nextrowac, 14) = "CB"
Nextrowac = Nextrowac + 1
End Sub
Private Sub ecriture()
For j = 2 To finalrowb
numboutique = Boutiques.Sheets(1).Cells(j, 1).Value
numMagA = ADYEN.Cells(i, 38).Value
If numMagA = numboutique Then
Call ecriturecpta
End If
Next j
End Sub
'*******************************************************************************************************************************************
'* numéro de compte banque et journal en fonction de la ste *
'*******************************************************************************************************************************************
Private Sub comptecpta()
If Left(ADYEN.Cells(i, 2), 5) = "G0006" Then
adyencpta.Cells(Nextrowac, 7) = "512140"
adyencpta.Cells(Nextrowac, 3) = "BNP-E CB"
ElseIf Left(ADYEN.Cells(i, 2), 5) = "G0017" Then
adyencpta.Cells(Nextrowac, 7) = "512540"
adyencpta.Cells(Nextrowac, 3) = "SG-EUR-CARTES"
ElseIf Left(ADYEN.Cells(i, 2), 5) = "G0027" Then
adyencpta.Cells(Nextrowac, 7) = "512300"
adyencpta.Cells(Nextrowac, 3) = "HSBC-EUR"
End If
End Sub
'*******************************************************************************************************************************************
'* Comptabilisation du brut et des frais dans 511 *
'*******************************************************************************************************************************************
Private Sub ecriturecpta()
' type ecriture general pour brut
adyencpta.Cells(Nextrowac, 1) = mag.Cells(j, 6)
Call ecriturecptacorp
Nextrowac = Nextrowac + 1
'type ecriture echeance pour brut
adyencpta.Cells(Nextrowac, 1) = mag.Cells(j, 8)
Call ecriturecptacorp
Nextrowac = Nextrowac + 1
If CDbl(ADYEN.Cells(i, 17)) + CDbl(ADYEN.Cells(i, 18)) + CDbl(ADYEN.Cells(i, 19)) + CDbl(ADYEN.Cells(i, 20)) + CDbl(ADYEN.Cells(i, 21)) > 0 Then
'type ecriture general pour frais
adyencpta.Cells(Nextrowac, 1) = mag.Cells(j, 6)
Call fraisbrut
Nextrowac = Nextrowac + 1
adyencpta.Cells(Nextrowac, 1) = mag.Cells(j, 7)
Call fraisbrut
adyencpta.Cells(Nextrowac, 15) = mag.Cells(j, 1)
Nextrowac = Nextrowac + 1
End If
End Sub
Private Sub fraisbrut()
'numero de societe
adyencpta.Cells(Nextrowac, 2) = mag.Cells(j, 11)
'code journal
adyencpta.Cells(Nextrowac, 3) = mag.Cells(j, 12)
'type de piece
adyencpta.Cells(Nextrowac, 4) = mag.Cells(j, 13)
adyencpta.Cells(Nextrowac, 5) = CDate(adyencpta.Cells(1, 5))
adyencpta.Cells(Nextrowac, 6) = CDate(adyencpta.Cells(1, 5))
If ADYEN.Cells(i, 5) = "wechatpay_pos" Then
adyencpta.Cells(Nextrowac, 9) = "FRAIS" & " " & mag.Cells(j, 24) & " " & mag.Cells(j, 1) & " " & mag.Cells(j, 2) & " " & CDate(adyencpta.Cells(1, 5))
adyencpta.Cells(Nextrowac, 7) = mag.Cells(j, 10)
adyencpta.Cells(Nextrowac, 14) = "WCP"
ElseIf ADYEN.Cells(i, 5) = "alipay" Then
adyencpta.Cells(Nextrowac, 9) = "FRAIS" & " " & mag.Cells(j, 26) & " " & mag.Cells(j, 1) & " " & mag.Cells(j, 2) & " " & CDate(adyencpta.Cells(1, 5))
adyencpta.Cells(Nextrowac, 7) = mag.Cells(j, 10)
adyencpta.Cells(Nextrowac, 14) = "ALP"
ElseIf ADYEN.Cells(i, 5) = "visa" Or ADYEN.Cells(i, 5) = "mc" Or ADYEN.Cells(i, 5) = "diners" Or ADYEN.Cells(i, 5) = "discover" Or ADYEN.Cells(i, 5) = "maestro" Then
adyencpta.Cells(Nextrowac, 9) = "FRAIS" & " " & mag.Cells(j, 16) & " " & mag.Cells(j, 1) & " " & mag.Cells(j, 2) & " " & CDate(adyencpta.Cells(1, 5))
adyencpta.Cells(Nextrowac, 7) = mag.Cells(j, 10)
adyencpta.Cells(Nextrowac, 14) = "CB"
End If
If ADYEN.Cells(i, 12) > 0 Then
adyencpta.Cells(Nextrowac, 11) = CDbl(ADYEN.Cells(i, 17)) + CDbl(ADYEN.Cells(i, 18)) + CDbl(ADYEN.Cells(i, 19)) + CDbl(ADYEN.Cells(i, 20)) - CDbl(ADYEN.Cells(i, 21))
adyencpta.Cells(Nextrowac, 10) = "D"
ElseIf ADYEN.Cells(i, 11) > 0 Then
adyencpta.Cells(Nextrowac, 11) = CDbl(ADYEN.Cells(i, 17)) + CDbl(ADYEN.Cells(i, 18)) + CDbl(ADYEN.Cells(i, 19)) + CDbl(ADYEN.Cells(i, 20)) - CDbl(ADYEN.Cells(i, 21))
adyencpta.Cells(Nextrowac, 10) = "C"
End If
adyencpta.Cells(Nextrowac, 13) = CDate(Mid(ADYEN.Cells(i, 6), 1, 10))
End Sub
Private Sub ecriturecptacorp()
'numéro de societe
adyencpta.Cells(Nextrowac, 2) = mag.Cells(j, 11)
'journal bancaire
adyencpta.Cells(Nextrowac, 3) = mag.Cells(j, 12)
'type de piece
adyencpta.Cells(Nextrowac, 4) = mag.Cells(j, 13)
'date d operation
adyencpta.Cells(Nextrowac, 5) = CDate(adyencpta.Cells(1, 5))
'date de valeur
adyencpta.Cells(Nextrowac, 6) = CDate(adyencpta.Cells(1, 5))
'******************************************************************************************************************************************
'*libelle et 511 associer au mode de paiement et mode de reglement
'******************************************************************************************************************************************
If ADYEN.Cells(i, 5) = "wechatpay_pos" Then
adyencpta.Cells(Nextrowac, 9) = mag.Cells(j, 24) & " " & mag.Cells(j, 1) & " " & mag.Cells(j, 2)
adyencpta.Cells(Nextrowac, 7) = mag.Cells(j, 25)
adyencpta.Cells(Nextrowac, 14) = "WCP"
ElseIf ADYEN.Cells(i, 5) = "alipay" Then
adyencpta.Cells(Nextrowac, 9) = mag.Cells(j, 26) & " " & mag.Cells(j, 1) & " " & mag.Cells(j, 2)
adyencpta.Cells(Nextrowac, 7) = mag.Cells(j, 27)
adyencpta.Cells(Nextrowac, 14) = "ALP"
ElseIf ADYEN.Cells(i, 5) = "visa" Or ADYEN.Cells(i, 5) = "mc" Or ADYEN.Cells(i, 5) = "diners" Or ADYEN.Cells(i, 5) = "discover" Or ADYEN.Cells(i, 5) = "maestro" Then
'libelle de la piece
adyencpta.Cells(Nextrowac, 9) = mag.Cells(j, 16) & " " & mag.Cells(j, 1) & " " & mag.Cells(j, 2)
'numero de compte attache au mode paiement ex visa=511300
adyencpta.Cells(Nextrowac, 7) = mag.Cells(j, 17)
'mode de paiement
adyencpta.Cells(Nextrowac, 14) = "CB"
ElseIf ADYEN.Cells(i, 5) = "amex" Then
adyencpta.Cells(Nextrowac, 9) = mag.Cells(j, 30) & " " & mag.Cells(j, 1) & " " & mag.Cells(j, 2)
adyencpta.Cells(Nextrowac, 7) = mag.Cells(j, 31)
adyencpta.Cells(Nextrowac, 14) = "am"
End If
'*****************************************************************************************************************************************
'* TEST SI TRANSACTION ENCAISSEMENT OU REMBOURSEMENT
'*****************************************************************************************************************************************
If ADYEN.Cells(i, 12) > 0 Then
'montant brut
adyencpta.Cells(Nextrowac, 11) = ADYEN.Cells(i, 12)
'sens de l'ecriture
adyencpta.Cells(Nextrowac, 10) = "C"
ElseIf ADYEN.Cells(i, 11) > 0 Then
adyencpta.Cells(Nextrowac, 11) = ADYEN.Cells(i, 11)
adyencpta.Cells(Nextrowac, 10) = "D"
End If
'date de vente
adyencpta.Cells(Nextrowac, 13) = CDate(Mid(ADYEN.Cells(i, 6), 1, 10))
End Sub
Private Sub sauvegarde()
ActiveWorkbook.Sheets(2).SaveAs FileName:= _
"G:\***************\" & Range("B1") & "_" & ActiveWorkbook.Name & ".csv", FileFormat:=xlCSV, _
CreateBackup:=False, Local:=True
End Sub