Comptage de A dans une ligne

funkay91 Messages postés 20 Date d'inscription mercredi 9 novembre 2005 Statut Membre Dernière intervention 22 novembre 2005 - 9 nov. 2005 à 11:35
funkay91 Messages postés 20 Date d'inscription mercredi 9 novembre 2005 Statut Membre Dernière intervention 22 novembre 2005 - 9 nov. 2005 à 16:41
Bon ceci est une partie d'une macro

For Each c In Range(Cells(6, 3), Cells(6, 56))
If c.Value() = "A" Then
NbA = NbA + 1
End If

Next c

je voudrai savoir si cette boucle permet de compter avec Nba le nombre de A dans ma ligne 6

3 réponses

cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
9 nov. 2005 à 12:12
Non du tout, ca te comptera le nombre de cellule donc le contenu est "A".



Pour faire ce que tu veux :



dim sTemp as string

dim NbA as integer



For Each c In Range(Cells(6, 3), Cells(6, 56))

sTemp = Replace(ucase(c.value()), ucase("a"), "")

NbA = NbA + (len(c.value()) - len(sTemp)

Next c

_____________________________________________________________________
DarK Sidious

Un API Viewer (pour le VB, VB.NET, C, C# et Delphi) tout en français : www.ProgOtoP.com/popapi/
0
jpleroisse Messages postés 1788 Date d'inscription mardi 7 novembre 2000 Statut Membre Dernière intervention 11 mars 2006 27
9 nov. 2005 à 13:42
Bonjour,

Si tu es sur Excel 97, la fonction Replace n'est pas reconnue.(Sur les versions supérieurs, je ne sais pas)



Sub Test()

Dim c As Range, NbA

For Each c In Range(Cells(6, 3), Cells(6, 56))

If c.Value() = "A" Then

NbA = NbA + 1

End If

Next c

MsgBox "Il y a " & NbA & " A dans la ligne 6 "

End Sub



jpleroisse



Si une réponse vous convient, cliquez Réponse Acceptée.
0
funkay91 Messages postés 20 Date d'inscription mercredi 9 novembre 2005 Statut Membre Dernière intervention 22 novembre 2005
9 nov. 2005 à 16:41
Sub essaie()
Dim Cellule As Byte
Dim NbA As Integer
Dim NbB As Integer
Dim NbC As Integer
NbA = 0
NbB = 0
NbC = 0
NbN = 0
Dim Valeur As String
Dim Couleur As Integer


Cells(4, 61) = "nombre de A"
Cells(4, 62) = "nombre de B"
Cells(4, 63) = "nombre de N"

For LinIndex = 6 To 37
With Cells(LinIndex, 3)
Couleur = .Interior.ColorIndex
'MsgBox ("couleur de ligne")
'MsgBox ("la couleur de la ligne est" & Couleur)
End With
If Couleur = -4142 Then
For Colindex = 4 To 59
With Cells(LinIndex, Colindex)
Couleur = .Interior.ColorIndex
'MsgBox ("la clouleur de la cellule" & Couleur)
If Couleur = -4142 Then
Valeur = .Value()
'MsgBox (Luc) If Valeur "AA" Or Valeur "A1" Or Valeur = "A-1A" Or Valeur = "A-2A" Then
NbA = NbA + 1
End If
If Valeur "B1" Or Valeur "BB" Or Valeur = "B 1" Then
NbB = NbB + 1
End If
If Valeur "NN" Or Valeur "CC" Then
NbN = NbN + 1
End If
End If

End With
Next Colindex
'calcul en semaine
calculA = 3 - NbA
calculB = 3 - NbB
calculN = 6 - NbN
If calculA = 0 Then
Cells(LinIndex, Colindex + 1) = "Ok"
ElseIf calculA < 0 Then
Cells(LinIndex, Colindex + 1) = "+" & -calculA & " personne(s)"
Else
Cells(LinIndex, Colindex + 1) = "manque " & calculA
End If
NbA = 0

If calculB = 0 Then
Cells(LinIndex, Colindex + 2) = "Ok"
ElseIf calculB < 0 Then
Cells(LinIndex, Colindex + 2) = "+" & -calculB & " personne(s)"
Else
Cells(LinIndex, Colindex + 2) = "manque " & calculB
End If
NbB = 0

If calculN = 0 Then
Cells(LinIndex, Colindex + 3) = "Ok"
ElseIf calculN < 0 Then
Cells(LinIndex, Colindex + 3) = "+" & -calculN & " personne(s)"
Else
Cells(LinIndex, Colindex + 3) = "manque " & calculN
End If
NbN = 0
End If
If Couleur = 33 Then
For Colindex = 4 To 59
With Cells(LinIndex, Colindex)
Couleur = .Interior.ColorIndex
'MsgBox (Couleur & "est la couleur de la cellule")
If Couleur = 33 Then
Valeur = .Value()
'MsgBox (Luc) If Valeur "AA" Or Valeur "A1" Or Valeur = "A-1A" Or Valeur = "A-2A" Then
NbA = NbA + 1
End If
If Valeur "B1" Or Valeur "BB" Then
NbB = NbB + 1
End If
If Valeur "NN" Or Valeur "CC" Then
NbN = NbN + 1
End If
End If

End With
Next Colindex
jour = Cells(LinIndex, 3)
'MsgBox (jour)
If jour = "S" Then
'MsgBox (NbA)
'calcul le samedi
calculA = 5 - NbA
calculB = 3 - NbB
calculN = 6 - NbN
If calculA = 0 Then
Cells(LinIndex, Colindex + 1) = "Ok"
ElseIf calculA < 0 Then
Cells(LinIndex, Colindex + 1) = "+" & -calculA & " personne(s)"
Else
Cells(LinIndex, Colindex + 1) = "manque " & calculA
End If
NbA = 0

If calculB = 0 Then
Cells(LinIndex, Colindex + 2) = "Ok"
ElseIf calculB < 0 Then
Cells(LinIndex, Colindex + 2) = "+" & -calculB & " personne(s)"
Else
Cells(LinIndex, Colindex + 2) = "manque " & calculB
End If
NbB = 0

If calculN = 0 Then
Cells(LinIndex, Colindex + 3) = "Ok"
ElseIf calculN < 0 Then
Cells(LinIndex, Colindex + 3) = "+" & -calculN & " personne(s)"
Else
Cells(LinIndex, Colindex + 3) = "manque " & calculN
End If
NbN = 0
Else
'calcul du dimanche et jour férié
calculA = 3 - NbA
calculB = 3 - NbB
calculN = 6 - NbN
If calculA = 0 Then
Cells(LinIndex, Colindex + 1) = "Ok"
ElseIf calculA < 0 Then
Cells(LinIndex, Colindex + 1) = "+" & -calculA & " personne(s)"
Else
Cells(LinIndex, Colindex + 1) = "manque " & calculA
End If
NbA = 0

If calculB = 0 Then
Cells(LinIndex, Colindex + 2) = "Ok"
ElseIf calculB < 0 Then
Cells(LinIndex, Colindex + 2) = "+" & -calculB & " personne(s)"
Else
Cells(LinIndex, Colindex + 2) = "manque " & calculB
End If
NbB = 0

If calculN = 0 Then
Cells(LinIndex, Colindex + 3) = "Ok"
ElseIf calculN < 0 Then
Cells(LinIndex, Colindex + 3) = "+" & -calculN & " personne(s)"
Else
Cells(LinIndex, Colindex + 3) = "manque " & calculN
End If
NbN = 0
End If


End If
Next LinIndex


'MsgBox ("NBA=" & NbA)
End Sub
Voila ma macro mais il me reste une question comment faire pour dès qu'il y a un A dans la cellule mon compteur s'incremente sans que je connaisse les valeurs à l'interieur
0
Rejoignez-nous