Faire une boucle de cellules

Fermé
crimoilefort - 31 oct. 2010 à 16:31
Le Pingou Messages postés 12035 Date d'inscription mercredi 11 août 2004 Statut Contributeur Dernière intervention 1 avril 2024 - 31 oct. 2010 à 21:30
Bonjour à vous tous,

Je voudrai effectuer une boucle de programme pour m'éviter de taper trop de lignes (je suis novice) --> je calcule le nombre de cellules d'une certaine couleur en fonction de son contenu :
Voici mon code (excel 2003):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim a, b, c, d, e, f, g, h, i, j, k, m, n, o, p, q, r As Range
Dim mon_0, mon_1, mon_2, mon_3, mon_4, mon_5, mon_6, mon_7, mon_8, mon_9, mon_10, mon_11, mon_12, mon_13, mon_14, mon_15, mon_16, mon_17, mon_18 As Double
Application.Volatile True

For Each a In [x10:Cd10]
If a = [C9] And a.Interior.ColorIndex = [C9].Interior.ColorIndex Then
mon_0 = mon_0 + 1
End If
Next
[c10] = mon_0
For Each b In [x11:Cd11]
If b = [C9] And b.Interior.ColorIndex = [C9].Interior.ColorIndex Then
mon_1 = mon_1 + 1
End If
Next
[c11] = mon_1
For Each c In [x12:Cd12]
If c = [C9] And c.Interior.ColorIndex = [C9].Interior.ColorIndex Then
mon_2 = mon_2 + 1
End If
Next
End Sub

En fait, je voudrai reconduire ma premiére boucle "FOR" sur 31 lignes et sur 18 colonnes (tableau).

Merci pour vos réponses.
@+
crimoilefort

1 réponse

Le Pingou Messages postés 12035 Date d'inscription mercredi 11 août 2004 Statut Contributeur Dernière intervention 1 avril 2024 1 425
31 oct. 2010 à 21:30
Bonjour,
Essayer la boucle comme ceci:
For Each a In [X10:CD41]
If a = [C9] And a.Interior.ColorIndex = [C9].Interior.ColorIndex Then
mon_0 = mon_0 + 1
End If
Next
--
Salutations.
Le Pingou
0