Salut à tous,
J'ai une petite appli sur Excel 2003 qui tourne depuis trois quatre ans maintenant.
Je cherche à la faire évoluer.
Il s'agit d'une application de facturation avec gestion des paiements.
J'ai réussi à faire les modif pour que les écritures comptables liées au paiement se créent mais je cherche à créer celle des deux mois précédents pour éviter de les saisir manuellement.
Mon code ne plante pas mais il ne traite que les deux premières lignes et après il tourne en rond.
Merci d'avance pour votre aide.
Sub CPTARGT()
Dim recherche As Range
Dim LVIDE As Range
Dim VDATE As Date
Dim MOIS As String
Dim test As String
VDATE = Format("01/07/2015", "dd/mm/yyyy")
Suivant:
With Sheets("PRODUCTION3").Range("N:N")
Set recherche = .Find(What:=VDATE, LookAt:=xlWhole, LookIn:=xlValues, searchdirection:=xlDown, SearchOrder:=xlByRows)
If Not recherche Is Nothing Then
firstAddress = recherche.Address
GoTo CPTAREG
Else
GoTo fin
End If
End With
boucle:
With Sheets("PRODUCTION3").Range("N:N")
Set recherche = .FindNext(recherche)
If Not recherche Is Nothing Or recherche.Address <> firstAddress Then
GoTo CPTAREG
VDATE = VDATE + 1
GoTo Suivant
End If
End With
CPTAREG:
With Sheets("RECUPPAIEMENT").Range("A:A")
Set LVIDE = .Find(What:="", LookAt:=xlWhole)
If Not LVIDE Is Nothing Then
End If
End With
With Sheets("PRODUCTION3")
If .Cells(recherche.Row, 15).Value = "CHQ" Then
GoTo boucle
Else
Sheets("RECUPPAIEMENT").Select
Cells(LVIDE.Row, 1).Value = Format(.Cells(recherche.Row, 14).Value, "ddmmyyyy")
If .Cells(recherche.Row, 15).Value = "CB" Then
Cells(LVIDE.Row, 2).Value = "CB"
Else: Cells(LVIDE.Row, 2).Value = "CA"
End If
Cells(LVIDE.Row, 3).Value = 41100000
MOIS = Format(Month(.Cells(recherche.Row, 4).Value), "00")
Cells(LVIDE.Row, 4).Value = "CREP" & MOIS
Cells(LVIDE.Row, 7).Value = .Cells(recherche.Row, 2).Value
Cells(LVIDE.Row, 5).Value = "C"
Cells(LVIDE.Row, 6).Value = .Cells(recherche.Row, 16).Value
Cells(LVIDE.Row, 8).Value = .Cells(recherche.Row, 5).Value
End If
End With
'ActiveWorkbook.Save
GoTo boucle
fin:
VDATE = VDATE + 1
With Sheets("PRODUCTION3").Range("N:N")
Set recherche = .Find(What:=VDATE, LookAt:=xlWhole, LookIn:=xlValues, searchdirection:=xlDown, SearchOrder:=xlByRows)
If Not recherche Is Nothing Then
firstAddress = recherche.Address
GoTo CPTAREG
Else
test = test + 1
If test < 2 Then
GoTo Suivant
Else
GoTo fin
End If
End If
End With
End Sub
J'ai une petite appli sur Excel 2003 qui tourne depuis trois quatre ans maintenant.
Je cherche à la faire évoluer.
Il s'agit d'une application de facturation avec gestion des paiements.
J'ai réussi à faire les modif pour que les écritures comptables liées au paiement se créent mais je cherche à créer celle des deux mois précédents pour éviter de les saisir manuellement.
Mon code ne plante pas mais il ne traite que les deux premières lignes et après il tourne en rond.
Merci d'avance pour votre aide.
Sub CPTARGT()
Dim recherche As Range
Dim LVIDE As Range
Dim VDATE As Date
Dim MOIS As String
Dim test As String
VDATE = Format("01/07/2015", "dd/mm/yyyy")
Suivant:
With Sheets("PRODUCTION3").Range("N:N")
Set recherche = .Find(What:=VDATE, LookAt:=xlWhole, LookIn:=xlValues, searchdirection:=xlDown, SearchOrder:=xlByRows)
If Not recherche Is Nothing Then
firstAddress = recherche.Address
GoTo CPTAREG
Else
GoTo fin
End If
End With
boucle:
With Sheets("PRODUCTION3").Range("N:N")
Set recherche = .FindNext(recherche)
If Not recherche Is Nothing Or recherche.Address <> firstAddress Then
GoTo CPTAREG
VDATE = VDATE + 1
GoTo Suivant
End If
End With
CPTAREG:
With Sheets("RECUPPAIEMENT").Range("A:A")
Set LVIDE = .Find(What:="", LookAt:=xlWhole)
If Not LVIDE Is Nothing Then
End If
End With
With Sheets("PRODUCTION3")
If .Cells(recherche.Row, 15).Value = "CHQ" Then
GoTo boucle
Else
Sheets("RECUPPAIEMENT").Select
Cells(LVIDE.Row, 1).Value = Format(.Cells(recherche.Row, 14).Value, "ddmmyyyy")
If .Cells(recherche.Row, 15).Value = "CB" Then
Cells(LVIDE.Row, 2).Value = "CB"
Else: Cells(LVIDE.Row, 2).Value = "CA"
End If
Cells(LVIDE.Row, 3).Value = 41100000
MOIS = Format(Month(.Cells(recherche.Row, 4).Value), "00")
Cells(LVIDE.Row, 4).Value = "CREP" & MOIS
Cells(LVIDE.Row, 7).Value = .Cells(recherche.Row, 2).Value
Cells(LVIDE.Row, 5).Value = "C"
Cells(LVIDE.Row, 6).Value = .Cells(recherche.Row, 16).Value
Cells(LVIDE.Row, 8).Value = .Cells(recherche.Row, 5).Value
End If
End With
'ActiveWorkbook.Save
GoTo boucle
fin:
VDATE = VDATE + 1
With Sheets("PRODUCTION3").Range("N:N")
Set recherche = .Find(What:=VDATE, LookAt:=xlWhole, LookIn:=xlValues, searchdirection:=xlDown, SearchOrder:=xlByRows)
If Not recherche Is Nothing Then
firstAddress = recherche.Address
GoTo CPTAREG
Else
test = test + 1
If test < 2 Then
GoTo Suivant
Else
GoTo fin
End If
End If
End With
End Sub
Pièces jointes
Dernière édition: