Bonjour a tous,
j'ai une macro qui contien bcp de If et je veux mettre a la place des If des case afin que mon code soit bien structuré
ma macro et
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 ub CouleursIndex1() For i = 3 To 167 For j = 6 To 14 If Cells(i, j) = Empty Or Cells(i, j).Value <> ED Or Cells(i, j).Value <> AF Or Cells(i, j).Value <> DP Or Cells(i, j).Value <> CB Or Cells(i, j).Value <> RO Or Cells(i, j).Value <> JPF Then Cells(i, j).Interior.ColorIndex = 0 End If If Cells(i, j).Value = "PG" Then Cells(i, j).Interior.ColorIndex = 3 End If If Cells(i, j).Value = "JPF" Then Cells(i, j).Interior.ColorIndex = 4 End If If Cells(i, j).Value = "RO" Then Cells(i, j).Interior.ColorIndex = 5 End If If Cells(i, j).Value = "CB" Then Cells(i, j).Interior.ColorIndex = 6 End If If Cells(i, j).Value = "DP" Then Cells(i, j).Interior.ColorIndex = 7 End If If Cells(i, j).Value = "AF" Then Cells(i, j).Interior.ColorIndex = 8 End If If Cells(i, j).Value = "ED" Then Cells(i, j).Interior.ColorIndex = 15 End If Next Next End Sub
pour remplcer les iF par des case j'ai fait
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 Sub CouleursIndex3() Dim i As Integer Dim j As Integer For i = 3 To 167 For j = 6 To 14 Select Case Cells(i, j) Case Cells(i, j) = Empty Or Cells(i, j).Value <> ED Or Cells(i, j).Value <> AF _ Or Cells(i, j).Value <> DP Or Cells(i, j).Value <> CB Or Cells(i, j).Value <> RO _ Or Cells(i, j).Value <> JPF Cells(i, j).Interior.ColorIndex = 0 Case Cells(i, j).Value = "PG" Cells(i, j).Interior.ColorIndex = 3 Case Cells(i, j).Value = "JPF" Cells(i, j).Interior.ColorIndex = 4 Case Cells(i, j).Value = "RO" Cells(i, j).Interior.ColorIndex = 5 Case Cells(i, j).Value = "CB" Cells(i, j).Interior.ColorIndex = 6 Case Cells(i, j).Value = "DP" Cells(i, j).Interior.ColorIndex = 7 Case Cells(i, j).Value = "AF" Cells(i, j).Interior.ColorIndex = 8 Case Cells(i, j).Value = "ED" Cells(i, j).Interior.ColorIndex = 15 End Select Next Next End Sub
mais sa na pas bien marché , par ce que la macro devvrais colorée selon certains conditions . la macro des Case donne a toutes les cellules la même couleur ui est le Rouge.
merci de m'expliquer commment sa marche la Condition Case
Partager