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

Compter les 2 premières occurrences de chaque série contenue dans une zone

3 réponses
Avatar
johnlito
Bonjour,
Je recherche une formule qui compte le nombre d'occurrences de "M" et qui passe à la série suivante quand il a compté les deux premiers de la série.
Je dois compter les deux premiers pour chaque série d'une plage définie (inférieur ou égal à 2)

Voici un exemple :
a a M c c M M M b a a M b b
ici le compte doit-être égal à 4

-------------------------------------------
M M M M b b M M a a M M M M
ici le compte doit-être 6


Merci pour votre aide.
Cordialement
john

3 réponses

Avatar
Philippe.R
Bonsoir,
En admettant que tes séries sont réparties à raison d'1 caractère par
cellule (si ce n'est le cas, utiliser Données / convertir), que la 1ère
colonne est laissée vide et que la plage dans laquelle les séries se
trouvent est nommée "maplage", la procédure ci dessous inscrira le décompte
à la fin de chaque ligne

Sub chrchecpte()
Dim cPt As Integer, cpS As Integer, i As Long, j As Integer, _
zzz As Long
zzz = Range("maplage").Rows.Count
For i = Range("maplage").Row To zzz + Range("maplage").Row
For j = 2 To Range("iv" & i).End(xlToLeft).Column
If Cells(i, j).Value = "M" Then
cPt = cPt + 1
ElseIf cPt > 1 And Cells(i, j).Value <> "M" Then
If Cells(i, j - 1).Value = "M" Then cpS = cpS + 1
If cpS > 1 Then
Cells(i, Range("iv" & i).End(xlToLeft).Column _
+ 1).Value = cPt
cPt = 0
cpS = 0
Exit For
End If
End If
' MsgBox cPt & " sur la ligne " & i & " en colonne " & j _
' & vbNewLine & cpS & " séries"
Next j
Next i
End Sub
--
Avec plaisir
http://dj.joss.free.fr/trombine.htm
http://jacxl.free.fr/mpfe/trombino.html
Philippe.R
Pour se connecter au forum :
http://www.excelabo.net/mpfe/connexion.php
News://news.microsoft.com/microsoft.public.fr.excel
"johnlito" a écrit dans le message de
news:
Bonjour,
Je recherche une formule qui compte le nombre d'occurrences de "M" et qui
passe
à la série suivante quand il a compté les deux premiers de la série.
Je dois compter les deux premiers pour chaque série d'une plage définie
(inférieur ou égal à 2)

Voici un exemple :
a a M c c M M M b a a M b b
ici le compte doit-être égal à 4

-------------------------------------------
M M M M b b M M a a M M M M
ici le compte doit-être 6


Merci pour votre aide.
Cordialement
john


Avatar
Philippe.R
Oups !
Disons plutôt :

Sub chrchecpte()
Dim cPt As Integer, cpS As Integer, i As Long, j As Integer, _
zzz As Long
zzz = Range("maplage").Rows.Count
For i = Range("maplage").Row To zzz + Range("maplage").Row
For j = 2 To Range("iv" & i).End(xlToLeft).Column
If Cells(i, j).Value = "M" Then
cPt = cPt + 1
ElseIf Cells(i, j).Value <> "M" Then
If Cells(i, j - 1).Value = "M" Then cpS = cpS + 1
If cpS > 1 Then
Cells(i, Range("iv" & i).End(xlToLeft).Column _
+ 1).Value = cPt
cPt = 0
cpS = 0
Exit For
End If
End If
' MsgBox cPt & " sur la ligne " & i & " en colonne " & j _
' & vbNewLine & cpS & " séries"
Next j
Next i
End Sub

--
Avec plaisir
http://dj.joss.free.fr/trombine.htm
http://jacxl.free.fr/mpfe/trombino.html
Philippe.R
Pour se connecter au forum :
http://www.excelabo.net/mpfe/connexion.php
News://news.microsoft.com/microsoft.public.fr.excel
"Philippe.R" <AS_rauphil_chez_wanadoo.fr> a écrit dans le message de
news:%
Bonsoir,
En admettant que tes séries sont réparties à raison d'1 caractère par
cellule (si ce n'est le cas, utiliser Données / convertir), que la 1ère
colonne est laissée vide et que la plage dans laquelle les séries se
trouvent est nommée "maplage", la procédure ci dessous inscrira le
décompte à la fin de chaque ligne

Sub chrchecpte()
Dim cPt As Integer, cpS As Integer, i As Long, j As Integer, _
zzz As Long
zzz = Range("maplage").Rows.Count
For i = Range("maplage").Row To zzz + Range("maplage").Row
For j = 2 To Range("iv" & i).End(xlToLeft).Column
If Cells(i, j).Value = "M" Then
cPt = cPt + 1
ElseIf cPt > 1 And Cells(i, j).Value <> "M" Then
If Cells(i, j - 1).Value = "M" Then cpS = cpS + 1
If cpS > 1 Then
Cells(i, Range("iv" & i).End(xlToLeft).Column _
+ 1).Value = cPt
cPt = 0
cpS = 0
Exit For
End If
End If
' MsgBox cPt & " sur la ligne " & i & " en colonne " & j _
' & vbNewLine & cpS & " séries"
Next j
Next i
End Sub
--
Avec plaisir
http://dj.joss.free.fr/trombine.htm
http://jacxl.free.fr/mpfe/trombino.html
Philippe.R
Pour se connecter au forum :
http://www.excelabo.net/mpfe/connexion.php
News://news.microsoft.com/microsoft.public.fr.excel
"johnlito" a écrit dans le message de
news:
Bonjour,
Je recherche une formule qui compte le nombre d'occurrences de "M" et qui
passe
à la série suivante quand il a compté les deux premiers de la série.
Je dois compter les deux premiers pour chaque série d'une plage définie
(inférieur ou égal à 2)

Voici un exemple :
a a M c c M M M b a a M b b
ici le compte doit-être égal à 4

-------------------------------------------
M M M M b b M M a a M M M M
ici le compte doit-être 6


Merci pour votre aide.
Cordialement
john





Avatar
Philippe.R
Re oups,
pour le cas où la deuxième série de M clos la ligne :

Sub chrchecpte()
'MPFE le 23/02/2009
Dim cPt As Integer, cpS As Integer, i As Long, j As Integer, _
zzz As Long
zzz = Range("maplage").Rows.Count
For i = Range("maplage").Row To zzz + Range("maplage").Row
For j = 2 To Range("iv" & i).End(xlToLeft).Column
If Cells(i, j).Value = "M" Then
cPt = cPt + 1
If j = Range("iv" & i).End(xlToLeft).Column Then
Cells(i, Range("iv" & i).End(xlToLeft).Column _
+ 1).Value = cPt
cPt = 0
cpS = 0
Exit For
End If
ElseIf Cells(i, j).Value <> "M" Then
If Cells(i, j - 1).Value = "M" Then cpS = cpS + 1
If cpS > 1 Then
Cells(i, Range("iv" & i).End(xlToLeft).Column _
+ 1).Value = cPt
cPt = 0
cpS = 0
Exit For
End If
End If
Next j
Next i
End Sub

--
Avec plaisir
http://dj.joss.free.fr/trombine.htm
http://jacxl.free.fr/mpfe/trombino.html
Philippe.R
Pour se connecter au forum :
http://www.excelabo.net/mpfe/connexion.php
News://news.microsoft.com/microsoft.public.fr.excel
[..]
"johnlito" a écrit dans le message de
news:
Bonjour,
Je recherche une formule qui compte le nombre d'occurrences de "M" et
qui passe
à la série suivante quand il a compté les deux premiers de la série.
Je dois compter les deux premiers pour chaque série d'une plage définie
(inférieur ou égal à 2)

Voici un exemple :
a a M c c M M M b a a M b b
ici le compte doit-être égal à 4

-------------------------------------------
M M M M b b M M a a M M M M
ici le compte doit-être 6


Merci pour votre aide.
Cordialement
john