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
| Dim Thecell As Range
'Pour éviter les ennuis, il vaut mieux toujours préciser sur quel classeur tu travailles.
Set S7 = ThisWorkbook.Sheets(7)
For Each S In ThisWorkbook.Worksheets(Array(1, 2))
'Nbl_12 = S.Range("B" & S.Rows.Count).End(xlUp).Row
'Tb = S.Range("B1:S" & Nbl_12)
'For x = 2 To UBound(Tb, 1)
'1ere erreur tu ne veux boucler que sur la colonne S en utilisant la colonne B uniquement pour définir le nombre de ligne
'Ca modifie le reste du code car TheCell représente maintenant les cellules de la colonne S (est non B)
For Each Thecell In S.Range("S1", S.Cells(S.Rows.Count, "B").End(xlUp).Offset(, 17))
'If Tb(x, 18) > 0 Then 'montant don
If Thecell > 0 Then 'il faudra peut-être corriger la valeur de l'offset)
i = Thecell.FormatConditions(1).Interior.ColorIndex 'récup index couleur fond S
'Nbl7 = S7.Range("B" & S7.Rows.Count).End(xlUp).Row + 1
'Si Sel n'est utilisé qu'une seule fois par la suite, tu peux intégrer "sa formule" directement dans la suite du code
'Sel = S.Range("B" & x & ":S" & x)
'Pour éviter de déclarer plein de variables NB12, NB17,... il est possible d'utiliser la structure With
With S7.Range("B" & S7.Rows.Count).End(xlUp).Offset(1, -1).Resize(1, 18)
'S7.Range("A" & Nbl7 & ":R" & Nbl7) = S.Range("B" & x & ":S" & x) 'Sel
'S7.Range("A" & Nbl7 & ":R" & Nbl7).Interior.ColorIndex = i 'appli index couleur fond S7
'2ème erreur
.Value = Thecell.Offset(, -17).Resize(1, 18)
.Interior.ColorIndex = i
End With
End If
Next x
Next S
End Sub |
Partager