répéter une action à chaque ligne

G

gaetan

Guest
bonjour je débute en VBA et mon problème est simple.

je veux à chaque ligne de mon tableau faire la meme action suivante

'Ligne 8
Dim Cellule As Range
Dim total As Variant
Range('D8:AH8').Select
For Each Cellule In Selection
If Cellule.Interior.ColorIndex = 3 Then 'Rouge
total = total + Cellule.Count
End If
Next
Range('AI8') = total

cela necessite un compteur mais j'ai du mal à programmer tout cela et je ne sais meme pas si cela est possible :-(
merci de votre aide
 

PascalXLD

XLDnaute Barbatruc
Modérateur
Bonjour

essaies mais j'ai pas testé

Dim Cellule As Range
Dim total As Variant
Dim Plage as Range
Dim x as integer
for x = 2 to range('D65536').end(xlup).row
Set Plage =Range('D' & x & ':AH' & x)
For Each Cellule In Plage
If Cellule.Interior.ColorIndex = 3 Then 'Rouge
total = total + Cellule.Count
End If
Next
Range('AI' & x) = total
total=0
next
 

PascalXLD

XLDnaute Barbatruc
Modérateur
Bonjour

Si ça marche je viens de faire le test (mieux vaut tard que jamais)

Le seul hic peut-être c'est que je suis parti du fait que tu avais des données dans tes cellules

Si ce n'est pas le cas il faut modifier la ligne

for x = 2 to range('D65536').end(xlup).row

par

for x= ta première ligne to ta dernière ligne
 

Discussions similaires

Réponses
21
Affichages
386

Statistiques des forums

Discussions
312 496
Messages
2 088 978
Membres
103 996
dernier inscrit
KB4175