OVH Cloud OVH Cloud

correction

2 réponses
Avatar
Gerard
Bonjour

ca marche pas merci de me corriger
Sub Changecolor()
Sheets("CONTACTS").Unprotect TotoOk ' deprotege
For I = 5 To 1000 '1000 cellules scrutées
If Sheets("CONTACTS").Range("A" & I).Value =
Sheets("ACCUEIL").Range("F14").Value Then 'recherche valeur dans colonne A

Sheets("CONTACTS").Range("A" & I & ":O" & I).Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
'Selection.Delete Shift:=xlUp

Else
Exit For
End If
Next I

'reprotege la feuille
Sheets("CONTACTS").Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True, Password:=TotoOk
ActiveSheet.EnableSelection = xlUnlockedCells

End Sub

2 réponses

Avatar
Nicolas B.
Salut,

A mon avis, il n'y a pas besoin de Exit For, sinon la macro s'arrête à
la première cellule qui ne contient pas la valeur de F14 :

Sub Changecolor()
Sheets("CONTACTS").Unprotect TotoOk ' deprotege
For I = 5 To 1000 '1000 cellules scrutées
If Sheets("CONTACTS").Range("A" & I).Value Sheets("ACCUEIL").Range("F14").Value Then 'recherche valeur dans colonne A

Sheets("CONTACTS").Range("A" & I & ":O" & I).Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
'Selection.Delete Shift:=xlUp
End If
Next I

'reprotege la feuille
Sheets("CONTACTS").Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True, Password:=TotoOk
ActiveSheet.EnableSelection = xlUnlockedCells

End Sub

Tu peux aussi accélérer la macro en évitant les sélections : remplace ceci :
Sheets("CONTACTS").Range("A" & I & ":O" & I).Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

par :
With Sheets("CONTACTS").Range("A" & I & ":O" & _
I).Interior
.ColorIndex = 40
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With


A+
Nicolas B.

Bonjour

ca marche pas merci de me corriger
Sub Changecolor()
Sheets("CONTACTS").Unprotect TotoOk ' deprotege
For I = 5 To 1000 '1000 cellules scrutées
If Sheets("CONTACTS").Range("A" & I).Value =
Sheets("ACCUEIL").Range("F14").Value Then 'recherche valeur dans colonne A

Sheets("CONTACTS").Range("A" & I & ":O" & I).Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
'Selection.Delete Shift:=xlUp

Else
Exit For
End If
Next I

'reprotege la feuille
Sheets("CONTACTS").Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True, Password:=TotoOk
ActiveSheet.EnableSelection = xlUnlockedCells

End Sub




Avatar
Gerard
salut
tu as raison mais il faut que je garde Exit for, pour sortir de la boucle
des que le N° a ete trouvé, ce n'est pas la peine de le faire aller jusqu'a
1000, il faut simplement le placer juste avant le else.

voila ce que c'est d'aller trop vite

merci
A+ gerard
"Nicolas B." a écrit dans le message
de news:
Salut,

A mon avis, il n'y a pas besoin de Exit For, sinon la macro s'arrête à la
première cellule qui ne contient pas la valeur de F14 :

Sub Changecolor()
Sheets("CONTACTS").Unprotect TotoOk ' deprotege
For I = 5 To 1000 '1000 cellules scrutées
If Sheets("CONTACTS").Range("A" & I).Value > Sheets("ACCUEIL").Range("F14").Value Then 'recherche valeur dans colonne
A

Sheets("CONTACTS").Range("A" & I & ":O" & I).Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
'Selection.Delete Shift:=xlUp
End If
Next I

'reprotege la feuille
Sheets("CONTACTS").Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True, Password:=TotoOk
ActiveSheet.EnableSelection = xlUnlockedCells

End Sub

Tu peux aussi accélérer la macro en évitant les sélections : remplace ceci
:
Sheets("CONTACTS").Range("A" & I & ":O" & I).Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

par :
With Sheets("CONTACTS").Range("A" & I & ":O" & _
I).Interior
.ColorIndex = 40
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With


A+
Nicolas B.

Bonjour

ca marche pas merci de me corriger
Sub Changecolor()
Sheets("CONTACTS").Unprotect TotoOk ' deprotege
For I = 5 To 1000 '1000 cellules scrutées
If Sheets("CONTACTS").Range("A" & I).Value =
Sheets("ACCUEIL").Range("F14").Value Then 'recherche valeur dans colonne
A

Sheets("CONTACTS").Range("A" & I & ":O" & I).Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
'Selection.Delete Shift:=xlUp

Else
Exit For
End If
Next I

'reprotege la feuille
Sheets("CONTACTS").Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True, Password:=TotoOk
ActiveSheet.EnableSelection = xlUnlockedCells

End Sub