Faire une boucle

nicho

XLDnaute Occasionnel
salut a vous tous

je veut réaliser une boucle avec cette macro pour qu'elle fonctionne avec les cellules 12, 13, ...., 42

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "B12" Then
If Target.Value = Range("$A$1") Then
Range("C12") = ""
Range("D12") = ""
Range("E12") = ""
Range("G12") = ""
Range("H12") = ""
Range("I12") = ""
Range("K12") = ""
Range("L12") = ""
End If
End If
End Sub

merci pour votre aide
 
Dernière édition:

néné06

XLDnaute Accro
Re : Faire une boucle

Bonsoir Nicho,

Essayes ceci et dis nous ?

Programme non testé!!

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$12" and Target.Value = cells(1,1).value Then
for a= 12 to 42
cells(a,3)=""
cells(a,4)=""
cells(a,5)=""
cells(a,7)=""
cells(a,8)=""
cells(a,9)=""
cells(a,11)=""
cells(a,12)=""
next a
End If
End Sub

A+
 

nicho

XLDnaute Occasionnel
Re : Faire une boucle

en fait g fait une erreur dans mon code (que j'ai réctifié maintenant dsl)

If Target.Address = "B12" Then

non pas

If Target.Address = "$B$12" Then

le code va par ligne

exemple
si B12 = $A$1 les cellule C12 D12 E12 G12 H12 I12 K12 L12 = ""
si B13 = $A$1 le cellules C13 D13 E13 G13 H13 I13 K13 L13 = ""

jusqu'à la ligne 42

merci
 

néné06

XLDnaute Accro
Re : Faire une boucle

re,

Testé chez moi, cela fonctionne.
j'avais oublié:
Application.EnableEvents = False
Application.EnableEvents = True

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$12" And Target.Value = Cells(1, 1).Value Then
Application.EnableEvents = False
For a = 12 To 42
Cells(a, 3) = ""
Cells(a, 4) = ""
Cells(a, 5) = ""
Cells(a, 7) = ""
Cells(a, 8) = ""
Cells(a, 9) = ""
Cells(a, 11) = ""
Cells(a, 12) = ""
Next a
Application.EnableEvents = True
End If
End Sub

A+
 

nicho

XLDnaute Occasionnel
Re : Faire une boucle

merci néné06 mais c'est pas le résultat espérer dsl


mon but:
si B12 = $A$1 les cellules ( C12 D12 E12 G12 H12 I12 K12 L12 ) s'effacerons
si B13 = $A$1 les cellules ( C13 D13 E13 G13 H13 I13 K13 L13 ) s'effacerons

.......

si B42 = $A$1 les cellules ( C42 D42 E42 G42 H42 I42 K42 L42 ) s'effacerons

svp, merci
 
Dernière édition:

néné06

XLDnaute Accro
Re : Faire une boucle

Re,

Comme ceci ??

Private Sub Worksheet_Change(ByVal Target As Range)
For a = 12 To 42
Application.EnableEvents = False
If Target.Row = a And Target.Column = 2 And Target.Value = Cells(1, 1).Value Then
Cells(a, 3) = ""
Cells(a, 4) = ""
Cells(a, 5) = ""
Cells(a, 7) = ""
Cells(a, 8) = ""
Cells(a, 9) = ""
Cells(a, 11) = ""
Cells(a, 12) = ""
End If
Application.EnableEvents = True
Next a
End Sub

A+
 

Discussions similaires

Réponses
1
Affichages
266
Réponses
21
Affichages
386

Statistiques des forums

Discussions
312 492
Messages
2 088 930
Membres
103 984
dernier inscrit
maliko67