OVH Cloud OVH Cloud

Inutilement compliqué, peut-être ?

4 réponses
Avatar
garnote
Bonjour, Bonjour,

Le but est de sélectionner, par macro, toutes les
cellules de la plage nommée «tableau»
contenant des nombres pairs.
Peut-on élaguer ?

Sub Sélectionne_Nombres_Pairs()
Dim c As Range
On Error Resume Next
For Each c In Range("tableau")
If IsNumeric(c) Then
If c Mod 2 = 0 Then
i = i + 1
If i = 1 Then
Set ici = c
Else
Set ici = Union(ici, c)
End If
End If
End If
Next
ici.Select
End Sub

Serge

4 réponses

Avatar
isabelle
salut Serge,

Peut-on élaguer ?


pas de beaucoup,

Sub Sélectionne_Nombres_Pairs()
Dim c As Range
On Error Resume Next
For Each c In Range("tableau")
If IsNumeric(c.Value) Then
If c Mod 2 = 0 Then ici = ici & c.Address & ","
End If
Next
Range(Left(ici, Len(ici) - 1)).Select
End Sub

isabelle

Avatar
garnote
J'ai coupé un autre if :-)

Sub Sélectionne_Nombres_Pairs()
Dim c As Range
On Error Resume Next
For Each c In Range("tableau").SpecialCells(xlCellTypeConstants, 1)
If c Mod 2 = 0 Then ici = ici & c.Address & ","
Next
Range(Left(ici, Len(ici) - 1)).Select
End Sub

Serge

"isabelle" a écrit dans le message de news:

salut Serge,

Peut-on élaguer ?


pas de beaucoup,

Sub Sélectionne_Nombres_Pairs()
Dim c As Range
On Error Resume Next
For Each c In Range("tableau")
If IsNumeric(c.Value) Then
If c Mod 2 = 0 Then ici = ici & c.Address & ","
End If
Next
Range(Left(ici, Len(ici) - 1)).Select
End Sub

isabelle



Avatar
isabelle
très bonne idée !
isabelle


J'ai coupé un autre if :-)

Sub Sélectionne_Nombres_Pairs()
Dim c As Range
On Error Resume Next
For Each c In Range("tableau").SpecialCells(xlCellTypeConstants, 1)
If c Mod 2 = 0 Then ici = ici & c.Address & ","
Next
Range(Left(ici, Len(ici) - 1)).Select
End Sub

Serge

"isabelle" a écrit dans le message de news:

salut Serge,

Peut-on élaguer ?


pas de beaucoup,

Sub Sélectionne_Nombres_Pairs()
Dim c As Range
On Error Resume Next
For Each c In Range("tableau")
If IsNumeric(c.Value) Then
If c Mod 2 = 0 Then ici = ici & c.Address & ","
End If
Next
Range(Left(ici, Len(ici) - 1)).Select
End Sub

isabelle





Avatar
garnote
Ainsi que tes esperluettes !

Serge

très bonne idée !
isabelle