|
|
|
|
Bonjour,
A B C D E F G H I J
1 RU RP RP M M M M M RP RP
2 RP N N N N M RP RP RP N
3 RU RP RP M M M M RP RP RP
4 RU RP RP M M M M RP RP RP
1) Ma question est comment faire pour sélectionner en automatique chaque série de 3 R* et pas +. Ne pas sélectionner ni compter si + de 3 R* a la suite.
2) les comptabiliser et mettre le résultat dans une cellule à coté du tableau.
Merci beaucoup.
Configuration: Windows XP Internet Explorer 6.0
Bonjour
|
Bonsoir
|
Salut tout le monde,
|
Re,
Function trois_R(plage As Range) As Byte
'initialisation
lig = plage.Row
nbre_R = Application.CountIf(plage, "R*")
col = 256
suite = 1
'parcours les colonnes ayant un "R*"
For cptr = 1 To nbre_R
anc_col = col
col = Rows(1).Find("R*", Cells(lig, col), xlValues, xlWhole).Column
'si les les R* ne sont pas jointifs
If col <> anc_col + 1 Then
suite = 1
End If
'si les R* sont jointifs on additionne le nombre de jointifs
If col = anc_col + 1 Then
suite = suite + 1
End If
' si le nombre de jointifs est inf à 4
If suite < 4 Then
trois_R = trois_R + Int(suite / 3) 'int(suite/3)=0 tant que suite est <3
End If
Next
End Function
Cordialement, Michel
|
Re,
|
Bonjour,
|
Au cas où:
Sub compter_troisR()
Dim col As Byte, suite As Byte, lig As Byte, derlig As Byte
Dim nbre_R As Byte, cptr As Byte, anc_col As Byte, trois_R As Byte
'initialisation
col = 255
suite = 1
lig = 5
derlig = Range("B65536").End(3).Row
Application.ScreenUpdating = False
'Nettoie le tableau
reinitialiser
'parcourt les lignes
For lig = 5 To derlig Step 3
nbre_R = Application.CountIf(Range(Cells(lig, 2), Cells(lig, 32)), "R*")
'parcours les colonnes ayant un "R*"
For cptr = 1 To nbre_R
anc_col = col
col = Rows(lig).Find("R*", Cells(lig, col), xlValues, xlWhole).Column
'si les les R* ne sont pas jointifs
If col <> anc_col + 1 Then
suite = 1
End If
'si les R* sont jointifs on additionne le nombre de jointifs
If col = anc_col + 1 Then
suite = suite + 1
End If
'si le nomre de jointif est = 3
If suite = 3 Then
Range(Cells(lig, col - 2), Cells(lig, col)).Interior.ColorIndex = 35
End If
' si le nombre de jointifs est inf à 4
If suite < 4 Then
trois_R = trois_R + Int(suite / 3) 'int(suite/3)=0 tant que suite est <3
End If
Next cptr
Cells(lig, 33) = trois_R
trois_R = 0
Next lig
End Sub
Sub reinitialiser()
Range(Cells(5, 2), Cells(255, 32)).Interior.ColorIndex = xlNone
Range("AG5:AG255").ClearContents
End Sub
Cordialement, Michel |
Super, Michel ça prend forme.
|
Bonjour,
|
Bonsoir Michel,
|
Comme le problème m'a branché...
|
Bonsoir Michel,
|