Ne pas répeter la macro pour chaque ligne

Bonjour,

Dans l'exemple ci-dessous (le fichier est trop grand et je n'ai pas pu le joundre en zip), je reproduit une macro pour chaque ligne. Je pense que je me complique inutilement la vie mais peine à faire autrement...

Valable pour:

NombredeCellulesrouges() et Sub NombredeCellulesbleues()

Sub NombredeCellulesbleues()

' Ligne 25

Dim tot16 As Variant

Range("D25:AH25").Select

For Each Cellule In Selection

If Cellule.Interior.ColorIndex = 5 Then

tot16 = tot16 + Cellule.Count

End If

Next

Range("AJ25") = tot16

' Ligne 26

Dim tot17 As Variant

Range("D26:AH26").Select

For Each Cellule In Selection

If Cellule.Interior.ColorIndex = 5 Then

tot17 = tot17 + Cellule.Count

End If

Next

Range("AJ26") = tot17

' Ligne 27

Dim tot18 As Variant

Range("D27:AH27").Select

For Each Cellule In Selection

If Cellule.Interior.ColorIndex = 5 Then

tot17 = tot17 + Cellule.Count

End If

Next

Range("AJ27") = tot18

ActiveCell.Offset(-11, 31).Range("A1").Select

End Sub

D'avance un immense merci pour votre aide...

Bien à vous

FBF

Bonjour,

ça peut faire quelque chose comme ça :

Sub NombredeCellulesbleues()
Dim FRow%, LRow%, i%, k%, Total%
FRow = 25 'première ligne traitée
LRow = 27 'dernière ligne traitée
For i = FRow To LRow
   For k = 4 To 34 '(34 = colonne AH)
      If Cells(i, k).Interior.ColorIndex = 5 Then Total = Total + 1
   Next
Cells(i, 36) = Total
Total = 0
Next
End Sub

A+

Ben... Ca marche méchamment...

Ouah!!

Je suis bluffé

Un énorme MERCI!!!

Je vous souhaite une excellente journée à la hauteur de l'aide que vous m'avez apportée

FBF

Rechercher des sujets similaires à "pas repeter macro chaque ligne"