Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

vba petit pb de boucle

3 réponses
Avatar
j-pascal
Bonsoir,

Pensant avoir compris le conseil de ce jour de FFO, j'ai voulu
l'appliquer à ce qui suit ; ça ne fonctionne pas !

(Nota : la première partie est censée remplacé ce qui est commenté)

'--------------

Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer

For i = 9 To 14
If Cells(2, i) <> "Trié" Then Range(Cells(2, i), Cells(65536,
i).End(xlUp)).Sort Key1:=Cells(2, i)
Next

' If [i2] <> "Trié" Then Range([b2], [b65536].End(xlUp)).Sort
Key1:=[b2]
' If [j2] <> "Trié" Then Range([c2], [c65536].End(xlUp)).Sort
Key1:=[c2]
' If [k2] <> "Trié" Then Range([d2], [d65536].End(xlUp)).Sort
Key1:=[d2]
' If [l2] <> "Trié" Then Range([e2], [e65536].End(xlUp)).Sort
Key1:=[e2]
' If [m2] <> "Trié" Then Range([f2], [f65536].End(xlUp)).Sort
Key1:=[f2]
' If [n2] <> "Trié" Then Range([g2], [g65536].End(xlUp)).Sort
Key1:=[g2]

End Sub

'--------------

Merci pour votre aide,

JP

3 réponses

Avatar
LSteph
Bonsoir,

j'aurais bien vu un select case
non!?

et avec un worksheet_change .. EnableEvents
irait bien.

@+

--
lSteph

j-pascal a écrit :
Bonsoir,

Pensant avoir compris le conseil de ce jour de FFO, j'ai voulu
l'appliquer à ce qui suit ; ça ne fonctionne pas !

(Nota : la première partie est censée remplacé ce qui est commenté)

'--------------

Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer

For i = 9 To 14
If Cells(2, i) <> "Trié" Then Range(Cells(2, i), Cells(65536,
i).End(xlUp)).Sort Key1:Îlls(2, i)
Next

' If [i2] <> "Trié" Then Range([b2], [b65536].End(xlUp)).Sort Key1:=[b2]
' If [j2] <> "Trié" Then Range([c2], [c65536].End(xlUp)).Sort Key1:=[c2]
' If [k2] <> "Trié" Then Range([d2], [d65536].End(xlUp)).Sort Key1:=[d2]
' If [l2] <> "Trié" Then Range([e2], [e65536].End(xlUp)).Sort Key1:=[e2]
' If [m2] <> "Trié" Then Range([f2], [f65536].End(xlUp)).Sort Key1:=[f2]
' If [n2] <> "Trié" Then Range([g2], [g65536].End(xlUp)).Sort Key1:=[g2]

End Sub

'--------------

Merci pour votre aide,

JP




Avatar
j-pascal
Bonsoir Stéphane,

Ok, je vais essayé (si je trouve car je n'ai jamais utilisé ...)

@+

JP

Bonsoir,

j'aurais bien vu un select case
non!?

et avec un worksheet_change .. EnableEvents
irait bien.

@+

--
lSteph

j-pascal a écrit :
Bonsoir,

Pensant avoir compris le conseil de ce jour de FFO, j'ai voulu l'appliquer
à ce qui suit ; ça ne fonctionne pas !

(Nota : la première partie est censée remplacé ce qui est commenté)

'--------------

Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer

For i = 9 To 14
If Cells(2, i) <> "Trié" Then Range(Cells(2, i), Cells(65536,
i).End(xlUp)).Sort Key1:Îlls(2, i)
Next

' If [i2] <> "Trié" Then Range([b2], [b65536].End(xlUp)).Sort Key1:=[b2]
' If [j2] <> "Trié" Then Range([c2], [c65536].End(xlUp)).Sort Key1:=[c2]
' If [k2] <> "Trié" Then Range([d2], [d65536].End(xlUp)).Sort Key1:=[d2]
' If [l2] <> "Trié" Then Range([e2], [e65536].End(xlUp)).Sort Key1:=[e2]
' If [m2] <> "Trié" Then Range([f2], [f65536].End(xlUp)).Sort Key1:=[f2]
' If [n2] <> "Trié" Then Range([g2], [g65536].End(xlUp)).Sort Key1:=[g2]

End Sub

'--------------

Merci pour votre aide,

JP






Avatar
j-pascal
Re,

Merci pour ta proposition.
Non, non, ce n'est pas encore ce soir que je m'initierai aux "Select
Case".

En fait, j'ai fait une erreur : si "I2" <> "trié", c'est la colonne "B"
qui doit être triée !! Donc il suffit de décaler la variable "i" de
"-7" et ça fonctionne !

If Cells(2, i) <> "Trié" Then Range(Cells(2, i - 7), Cells(65536, i -
7).End(xlUp)).Sort Key1:Îlls(2, i - 7)

@+ pour les select case

JP

PS : a priori le "Application.EnableEvents = True" si ce dont tu
parlais, n'est pas indispensable.

Bonsoir,

j'aurais bien vu un select case
non!?

et avec un worksheet_change .. EnableEvents
irait bien.

@+

--
lSteph

j-pascal a écrit :
Bonsoir,

Pensant avoir compris le conseil de ce jour de FFO, j'ai voulu l'appliquer
à ce qui suit ; ça ne fonctionne pas !

(Nota : la première partie est censée remplacé ce qui est commenté)

'--------------

Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer

For i = 9 To 14
If Cells(2, i) <> "Trié" Then Range(Cells(2, i), Cells(65536,
i).End(xlUp)).Sort Key1:Îlls(2, i)
Next

' If [i2] <> "Trié" Then Range([b2], [b65536].End(xlUp)).Sort Key1:=[b2]
' If [j2] <> "Trié" Then Range([c2], [c65536].End(xlUp)).Sort Key1:=[c2]
' If [k2] <> "Trié" Then Range([d2], [d65536].End(xlUp)).Sort Key1:=[d2]
' If [l2] <> "Trié" Then Range([e2], [e65536].End(xlUp)).Sort Key1:=[e2]
' If [m2] <> "Trié" Then Range([f2], [f65536].End(xlUp)).Sort Key1:=[f2]
' If [n2] <> "Trié" Then Range([g2], [g65536].End(xlUp)).Sort Key1:=[g2]

End Sub

'--------------

Merci pour votre aide,

JP