Sub maj_recap()
Dim myDa As Date
Dim myNoa As String
Dim myvalu As Single
myDa = Sheets("Balance").Range("C13").Value
myNoa = Sheets("system").Range("S17").Value
myvalu = Sheets("Balance").Range("D8").Value
Call call_recap(myDa, myNoa, myvalu)
End Sub
Sub call_recap(myD As Date, myNo As String, myVal As Single)
Dim fso As Object
Dim itEx As Boolean
Dim I, K As Integer
Dim J As Integer
'Dim celluletrouve As Cell
K = 0
'Ouverture du classeur Récapituatif-Remboursement.xlsx'
MyPath = ActiveWorkbook.Path ' On récupère le chemin actuel du classeur '
Set fso = CreateObject("Scripting.FileSystemObject") 'vérifie l'existence du fichier '
x = fso.FileExists(MyPath & "\Historique-Récapitulatif" & ".xlsx")
If x = True Then 'si oui, on ouvre ce fichier
Set wk = Workbooks.Open(Filename:=ThisWorkbook.Path & "\Historique-Récapitulatif" & ".xlsx")
wk.Activate
Application.Visible = True
' Trouver la ligne du bon numéro d'adherent "
With Sheets("Récapitulatif")
Set celluletrouve = wk.Sheets("Récapitulatif").Range("a4:a29").Find(myNo, LookIn:=xlValues, lookat:=xlWhole)
J = wk.Sheets("Récapitulatif").Range("a4:a29").Find(myNo, LookIn:=xlValues, lookat:=xlWhole).Row
End With
' Trouver la colonne de la bonne date '
With Sheets("Récapitulatif")
While K = 0
For I = 3 To 16382
If Cells(1, I) = myD Then ' On regarde si la date existe, si oui on donne à K le numéro de ligne '
K = I
Exit For
End If
Next
If K = 0 Then
For I = 3 To 16382
If Cells(1, I) = "" Then ' Si la date n'existe pas, on la met dans la premièe case vide
Cells(1, I) = myD
K = I
Exit For
End If
Next
End If
Wend
End With
MsgBox ("I = " & I & "J = " & J)
With Sheets("Récapitulatif")
Cells(J, I) = myVal
End With
'End With
Else: MsgBox " Pas de fichier"
End If
wk.Save
wk.Close
End Sub