Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Excel > Macros et VBA Excel
Macros et VBA Excel Vos questions relatives aux macros Excel, à l'utilisation de VBA et à l'automatisation de vos classeurs Excel.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 25/01/2012, 17h00   #1
Invité régulier
 
Inscription : décembre 2011
Messages : 31
Détails du profil
Informations forums :
Inscription : décembre 2011
Messages : 31
Points : 9
Points : 9
Par défaut Allègement de code

Bonjour Forum!!

j'aurais besoin d'un petit coup de main pour nettoyer et allège certaine partie de code...et je sais, certains vont hurler....mais je sais juste bidouiller des bouts de code (et merci à tous ceux qui m'y ont aidé!!) ou les enregistrer avec l'enregistreur d'excel..Donc ils fonctionnent mais sont super lourd...alors si quelqu'un avait 2 minutes, j'en serais extrèmement reconnaissante!!!

Un premier, particulièrement horrible je le conçois mais il permet de fusionner 5 lignes par cellules sur quasi 52 colonnes sauf la 7ème où il me faut absoluement mes 5 lignes.. (je sais la fusion de cellules c'est à éviter, mais j'ai pas trouver d'autres solutions dans mon cas...)

Code :
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
Sub Macro3()
' Création d'une nouvelle évaluation avec plusieurs lignes pour la case "classe pharmacothérapeutique" tout en gardant la protection de la feuille
' (=CommandButton2 création d'une nouvelle évaluation feuille "tableau")
 
    ActiveSheet.Unprotect
 
    ActiveCell.Range("A1:A6").Select
    Selection.EntireRow.Hidden = False
    Call Macro10
 
    ActiveCell.Offset(1, 0).Range("A1:A4").Select
    Selection.ClearContents
    ActiveCell.Offset(0, 25).Range("A1:E4").Select
    Selection.ClearContents
    ActiveCell.Offset(0, 6).Range("A1:C4").Select
    Selection.ClearContents
    ActiveCell.Offset(0, 5).Range("A1:D4").Select
    Selection.ClearContents
    ActiveCell.Offset(0, 5).Range("A1:A4").Select
    Selection.ClearContents
    ActiveCell.Offset(-1, -41).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    Selection.Copy
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    Selection.Copy
    ActiveCell.Offset(0, 2).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    Application.CutCopyMode = False
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    Selection.Copy
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    Application.CutCopyMode = False
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, 1).Range("A1:A5").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.Offset(0, -50).Range("A1:A5").Select
    ActiveCell.FormulaR1C1 = "=TODAY()"
     Selection.Merge
    ActiveCell.Offset(0, -1).Range("A1:A5").Select
       Call Macro6
 
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Pour infos macro10:

Code :
1
2
3
4
5
6
7
8
9
10
11
Sub Macro10()
'Copie des formules la ligne précédente
 
    ActiveCell.Rows("1:1").EntireRow.Select
    Selection.AutoFill Destination:=ActiveCell.Rows("1:6").EntireRow, Type:= _
        xlFillDefault
    ActiveCell.Rows("1:6").EntireRow.Select
 
 
 
End Sub
et macro 6
Code :
1
2
3
4
5
6
7
Sub Macro6()
' permet l'attribution d'un nouveau numéro d'évaluation lors de la création d'une nouvelle ligne d'évaluation
' (=CommandButton2 création d'une nouvelle évaluation feuille "tableau")
 
       ActiveCell.FormulaR1C1 = _
        "=IF(ISBLANK(RC[1]),"""",IF(R[-1]C<>"""",R[-1]C+1,IF(R[-2]C<>"""",R[-2]C+1,IF(R[-3]C<>"""",R[-3]C+1,IF(R[-4]C<>"""",R[-4]C+1,R[-5]C+1)))))"
End Sub
Celui-ci serait également a simplifier. Il permet de masquer des lignes quand "NA" figure dans la colonne A de la ligne (peut être en faisant une boucle mais je n'y suis pas parvenu...) :

Code :
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
Sub macro7()
'Permet de masquer les lignes de rapport inutiles
 
Range("A1:Q120").Select
Selection.EntireRow.Hidden = False
 
If Range("a14") = "NA" Then
Rows("14").Select
Selection.EntireRow.Hidden = True
End If
 
If Range("a15") = "NA" Then
Rows("15").Select
Selection.EntireRow.Hidden = True
End If
 
If Range("a17") = "NA" Then
Rows("17").Select
Selection.EntireRow.Hidden = True
End If
 
If Range("a18") = "NA" Then
Rows("18").Select
Selection.EntireRow.Hidden = True
End If
 
If Range("a27") = "NA" Then
Rows("27").Select
Selection.EntireRow.Hidden = True
End If
 
If Range("a28") = "NA" Then
Rows("28").Select
Selection.EntireRow.Hidden = True
End If
 
If Range("a29") = "NA" Then
Rows("29").Select
Selection.EntireRow.Hidden = True
End If
 
If Range("a32") = "NA" Then
Rows("32").Select
Selection.EntireRow.Hidden = True
End If
 
If Range("a33") = "NA" Then
Rows("33").Select
Selection.EntireRow.Hidden = True
End If
 
If Range("a43") = "NA" Then
Rows("43").Select
Selection.EntireRow.Hidden = True
End If
 
If Range("a45") = "NA" Then
Rows("45").Select
Selection.EntireRow.Hidden = True
End If
 
If Range("a46") = "NA" Then
Rows("46").Select
Selection.EntireRow.Hidden = True
End If
 
If Range("j62") = "NA" Then
Rows("62").Select
Selection.EntireRow.Hidden = True
End If
 
If Range("a68") = "NA" Then
Rows("68").Select
Selection.EntireRow.Hidden = True
End If
 
If Range("a69") = "NA" Then
Rows("69").Select
Selection.EntireRow.Hidden = True
End If
 
End Sub
Merci par avance!!!
babou41287 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/01/2012, 17h45   #2
Invité de passage
 
Inscription : juillet 2009
Messages : 2
Détails du profil
Informations forums :
Inscription : juillet 2009
Messages : 2
Points : 2
Points : 2
Par défaut Allègement de code

Bonjour Forum et Bonjour Babou,
Toute instruction ".select" suivi de "selection." à la ligne suivante peut s'alleger.
Exemple:
Code :
1
2
ActiveCell.Range("A1:A6").Select
    Selection.EntireRow.Hidden = False
peut s'écrire :

Code :
ActiveCell.Range("A1:A6").EntireRow.Hidden = False
OU

Code :
1
2
3
ActiveCell.Rows("1:1").EntireRow.Select
    Selection.AutoFill Destination:=ActiveCell.Rows("1:6").EntireRow, Type:= _
        xlFillDefault
peut s'écrire:
Code :
1
2
ActiveCell.Rows("1:1").EntireRow.AutoFill Destination:=ActiveCell.Rows("1:6").EntireRow, Type:= _
        xlFillDefault
Voilà.
Bon courage
esipa07 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/01/2012, 12h11   #3
Invité régulier
 
Inscription : décembre 2011
Messages : 31
Détails du profil
Informations forums :
Inscription : décembre 2011
Messages : 31
Points : 9
Points : 9
Désolé de ne répondre que maintenant, mais j'étais quelque peu indisponible ce temps-ci!!

En tout cas Je te remercie beaucoup!! Et vais commencer par ça!!

Mais y aurait-il une solution pour faire une boucle qui permettrait qu'excel recherche toutes les lignes dont la colonne A aurait comme valeur "NA" et les masque, plutôt que de citer les lignes à chaque fois?
babou41287 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/01/2012, 14h02   #4
Membre Expert
 
Femme
Ingénieur développement logiciels
Inscription : juin 2007
Messages : 480
Détails du profil
Informations personnelles :
Sexe : Femme
Localisation : France, Ain (Rhône Alpes)

Informations professionnelles :
Activité : Ingénieur développement logiciels

Informations forums :
Inscription : juin 2007
Messages : 480
Points : 1 024
Points : 1 024
Bonjour,
Voici une proposition de boucle pour masquer les lignes avec "NA" (le .EntireRows ne servait à rien):
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Dim i As Integer
Dim tabNumLignes(14) As Integer
 
    tabNumLignes(0) = 14
    tabNumLignes(1) = 15
    tabNumLignes(2) = 17
    tabNumLignes(3) = 18
    tabNumLignes(4) = 27
    tabNumLignes(5) = 28
    tabNumLignes(6) = 29
    tabNumLignes(7) = 32
    tabNumLignes(8) = 33
    tabNumLignes(9) = 43
    tabNumLignes(10) = 45
    tabNumLignes(11) = 46
    tabNumLignes(12) = 62
    tabNumLignes(13) = 68
    tabNumLignes(14) = 69
 
    For i = 0 To 14
        If Range("a" & tabNumLignes(i)) = "NA" Then
            Rows(tabNumLignes(i)).Hidden = True
        End If
    Next i
tedo01 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/01/2012, 16h03   #5
Expert Confirmé
 
Philippe Tulliez
Développeur et formateur VBA, Excel et Word.
Inscription : janvier 2010
Messages : 1 313
Détails du profil
Informations personnelles :
Nom : Philippe Tulliez
Localisation : Belgique

Informations professionnelles :
Activité : Développeur et formateur VBA, Excel et Word.

Informations forums :
Inscription : janvier 2010
Messages : 1 313
Points : 2 679
Points : 2 679
Bonjour,
Une autre solution
Considérant que la feuille se nomme maFeuille et que c'est la colonne A qui contient des cellules avec comme valeur possible NA
Code :
1
2
3
4
5
6
7
Sub HiddenRow()
 Dim sht As Worksheet: Set sht = ThisWorkbook.Worksheets("maFeuille")
 Dim rng As Range
 For Each rng In sht.Range("A2:A" & sht.Range("A" & Rows.Count).End(xlUp).Row)
  If UCase(rng) = "NA" Then Rows(rng.Row).Hidden = True
 Next
End Sub
__________________
Philippe Tulliez
http://philippe.tulliez.be
Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément. (Nicolas Boileau)

Lorsque vous avez la réponse à votre question, n'oubliez pas de cliquer sur et si celle-ci est pertinente pensez à voter
corona est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/01/2012, 10h29   #6
Invité régulier
 
Inscription : décembre 2011
Messages : 31
Détails du profil
Informations forums :
Inscription : décembre 2011
Messages : 31
Points : 9
Points : 9
Merci beaucoup à corona et tedo01! Les deux solutions fonctionnent très bien.

Maintenant( si je n'abuse pas trop de le demander...) par rapport au premier code, est ce qu'il est possible de faire une boucle du type de celle que vous m'avez passée précédemment mais pour les colonnes cette fois?? En fait il faudrait que les 4 cellules qui suivent la ligne sélectionnée soit fusionnées et ce de la colonne A jusqu'à la AZ sauf la G.
Manuellement, ça me donne le code tout moche que j'ai mis dans mon premier post et j'aimerais vraiment alléger aussi...

Merci beaucoup beaucoup!!!
babou41287 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/02/2012, 10h12   #7
Membre Expert
 
Femme
Ingénieur développement logiciels
Inscription : juin 2007
Messages : 480
Détails du profil
Informations personnelles :
Sexe : Femme
Localisation : France, Ain (Rhône Alpes)

Informations professionnelles :
Activité : Ingénieur développement logiciels

Informations forums :
Inscription : juin 2007
Messages : 480
Points : 1 024
Points : 1 024
Bonjour,
Voici une boucle pour les colonnes :
Code :
1
2
3
4
5
6
7
Dim i As Integer
 
    For i = 0 To 5
        If i <> 6 Then
            ActiveCell.Offset(0, i).Range("A1:A5").Merge
        End If
    Next i
tedo01 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/02/2012, 15h15   #8
Invité régulier
 
Inscription : décembre 2011
Messages : 31
Détails du profil
Informations forums :
Inscription : décembre 2011
Messages : 31
Points : 9
Points : 9
ça marche très bien!!! Merci beaucoup!!!!
babou41287 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 00h45.


 
 
 
 
Partenaires

Hébergement Web