Bonjour,
J'essaie d'enregistrer un fichier via une macro vba, voici ma macro :
La ligne en jaune représente l'erreur que je rencontre, auriez-vous une idée? Merci beaucoup!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 Public Sub somme() Application.ScreenUpdating = False ' ws1= reference à la feuille des clients Set ws1 = Worksheets(1) ' i pointeur de ligne dans la feuille clients i = 4 ' nplc client en cours de traitement nplc = "" ' on parcourt la feuille des clients While ws1.Cells(i, "B") <> 0 ' si le numéro de client sur la ligne i est différent du client en cours If ws1.Cells(i, "B") <> nplc Then ' si client en cours est non blanc If nplc <> "" Then wb.SaveAs ws2.Name & ".xlsx" wb.Close End If ' on crée un nouveau classeur extrait client ' wb classeur extrait client Set wb = Workbooks.Add ' ws2 feuille extrait client Set ws2 = wb.Worksheets(1) ' nplc = client en cours nplc = ws1.Cells(i, "B") Application.StatusBar = "Client " & nplc & " en cours de création" Name_Feuille = ("OTOC_Service_") & nplc & ("_") & Format(Date, "dd-mm-yyyy") ' on copie la ligne ws1.Range("A3:I3").Copy ws2.Range("A1") ' j pointeur de ligne dans le classeur extrait client j = 1 End If ' si on n'a pas le statut = 0 sur cette ligne If Not (ws1.Range("A" & i)) = 0 Then ' incrémente pointeur de ligne j = j + 1 'on copie la ligne ws1.Rows(i).Copy ws2.Range("A" & j) Range("H" & j + 1 & ":I" & j + 1).Formula = "=SUM(H2:H" & j & ")" End If ' on passe à la ligne client suivante i = i + 1 Wend ' on enregistre le dernier classeur wb.SaveAs Name_Feuille & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled Application.ScreenUpdating = True Set ws1 = Nothing Set ws2 = Nothing Application.StatusBar = "traitement terminé" End Sub
Partager