Bonjour à tous,
J'avais déjà posté une autre question, mais le besoin ayant changé, je vous en repose une autre![]()
Voila, j'ai ce code :
Il fonctionne très bien, recréer bien le template + l'insertion des données au bon endroit.
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148 Sub CreationSynthese() ' Effacement de la feuille Cells.Delete ' Ouverture de SalesOps.xlsx : Workbooks.Open "C:\Users\a\Desktop\test_macro\SalesOps.xlsm" ' Ecriture du template : Range("A1") = " " Range("B1") = " " Range("C1") = "Agreement Type" Range("D1") = "Description" Range("E1") = "External description" Range("F1") = "Valid From" Range("G1") = "To" Range("H1") = "Currency" Range("I1") = "Release Status" Range("J1") = "" Range("K1") = "Sales Organization" Range("L1") = "Distribution Channel" Range("M1") = "Division" Range("N1") = "Sales district" Range("O1") = "Personnel number" Range("P1") = "" Range("Q1") = "Check Customer Electronic ord Compliance" Range("R1") = "Check Customer Loyalty Compliance" Range("S1") = "Check Customer POS Compliance" Range("T1") = "Check Weighted Avg Days to Pay" Range("U1") = "Weighted Avg Days to Pay Limit" Range("V1") = "Terms Agreement" Range("W1") = "Stop Rebate Payment" Range("Y1") = "Growth Base = Avg of Last 2 Years" Range("Z1") = "Growth Rebate Paid on Incremental Sales" Range("AA1") = "" Range("AB1") = "Quarterly Rebate Calculation Type" Range("AC1") = "Settlement Calendar" Range("AD1") = "" Range("AE1") = "Campaign ID" Range("AF1") = "Grouping" Range("AG1") = "Period Profile" Range("A3") = " " Range("B3") = " " Range("C3") = "Application" Range("D3") = "Condition Type" Range("E3") = "Table" Range("F3") = "" Range("G3") = "Pricing Region" Range("H3") = "Sales Organization" Range("I3") = "Sales district" Range("J3") = "Customer" Range("K3") = "Customer Tier" Range("L3") = "Sales Tier" Range("M3") = "Division" Range("N3") = "Profit Center" Range("O3") = "Main group" Range("P3") = "Group" Range("Q3") = "Subgroup" Range("R3") = "Subgroup" Range("S3") = "Material" Range("T3") = "Valid From" Range("U3") = "Valid To" Range("V3") = "Rate" Range("W3") = "Condition Currency" Range("A2") = "HDR" Range("A4") = "RULE" Range("A5") = "RULE" Range("A6") = "RULE" Range("A7") = "RULE" Range("A8") = "RULE" Range("A9") = "RULE" Range("A11") = "SCALE" Range("A12") = "SCALE" Range("A13") = "SCALE" Range("A14") = "~~~" Range("X9") = "Rates needs to be multiplied by 10" Range("X10") = "Scale value" Range("Y10") = "Scale quantity" Range("Z10") = "Condition Rate" ' Mise en forme de la ligne de titre : Range("A1:AG1").Interior.ColorIndex = 15 'gris Range("A1:AG1").Font.Bold = True Range("A3:W3").Interior.ColorIndex = 15 'gris Range("A3:W3").Font.Bold = True Range("X9").Font.Bold = True Range("X9").Font.ColorIndex = 3 Range("X10:Y10").Font.Bold = True Range("X10").Interior.ColorIndex = 15 Range("Y10").Interior.ColorIndex = 27 Range("Z10").Interior.ColorIndex = 15 ' Copie des données : Workbooks("SalesOps.xlsm").Sheets("YREB").Range("A4").Copy Workbooks("customer-1.xls").Activate Workbooks("customer-1.xls").Sheets("Feuil1").Range("K2").Select Workbooks("customer-1.xls").Sheets("Feuil1").Paste Workbooks("SalesOps.xlsm").Sheets("YREB").Range("C4").Copy Workbooks("customer-1.xls").Activate Workbooks("customer-1.xls").Sheets("Feuil1").Range("N2").Select Workbooks("customer-1.xls").Sheets("Feuil1").Paste Workbooks("SalesOps.xlsm").Sheets("YREB").Range("G4").Copy Workbooks("customer-1.xls").Activate Workbooks("customer-1.xls").Sheets("Feuil1").Range("H2").Select Workbooks("customer-1.xls").Sheets("Feuil1").Paste Workbooks("SalesOps.xlsm").Sheets("YREB").Range("H4").Copy Workbooks("customer-1.xls").Activate Workbooks("customer-1.xls").Sheets("Feuil1").Range("AC2").Select Workbooks("customer-1.xls").Sheets("Feuil1").Paste Workbooks("SalesOps.xlsm").Sheets("YREB").Range("I4").Copy Workbooks("customer-1.xls").Activate Workbooks("customer-1.xls").Sheets("Feuil1").Range("AB2").Select Workbooks("customer-1.xls").Sheets("Feuil1").Paste Workbooks("SalesOps.xlsm").Sheets("YREB").Range("J4").Copy Workbooks("customer-1.xls").Activate Workbooks("customer-1.xls").Sheets("Feuil1").Range("D2").Select Workbooks("customer-1.xls").Sheets("Feuil1").Paste Workbooks("SalesOps.xlsm").Sheets("YREB").Range("K4").Copy Workbooks("customer-1.xls").Activate Workbooks("customer-1.xls").Sheets("Feuil1").Range("E2").Select Workbooks("customer-1.xls").Sheets("Feuil1").Paste Workbooks("SalesOps.xlsm").Sheets("YREB").Range("L4").Copy Workbooks("customer-1.xls").Activate Workbooks("customer-1.xls").Sheets("Feuil1").Range("F2").Select Workbooks("customer-1.xls").Sheets("Feuil1").Paste Workbooks("SalesOps.xlsm").Sheets("YREB").Range("M4").Copy Workbooks("customer-1.xls").Activate Workbooks("customer-1.xls").Sheets("Feuil1").Range("G2").Select Workbooks("customer-1.xls").Sheets("Feuil1").Paste Workbooks("SalesOps.xlsm").Sheets("YREB").Range("OA4").Copy Workbooks("customer-1.xls").Activate Workbooks("customer-1.xls").Sheets("Feuil1").Range("O2").Select Workbooks("customer-1.xls").Sheets("Feuil1").Paste ' Fermeture de SalesOps.xlsx : Workbooks("SalesOps.xlsm").Close End Sub
Le problème c'est que ça va fonctionner pour une ligne... et non toutes les lignes du fichier SalesOps...
Alors comment créer une boucle pour que ça passe sur chaque ligne, et que pour chaque ligne, le template se repete, et que les données aillent bien au bon endroit? le tout sur un meme fichier.
En gros on a 2 lignes sur le fichier SalesOps, donc dans mon fichier customer-1, je devrais retrouver 2 fois le template à la suite avec les données placées au bon endroit
Merci d'avance pour votre aide!
Partager