calcul dans label + text box

arvin

XLDnaute Occasionnel
bonjour à tous ,

j'ai un souci : je souhaite calculer dans une colonne le nombre de 'a' et mettre le résultat dans un label et text box (userfrom) : la macro fonctionne mais mal , en fait il me calcule tous les a, b, c, dans 1 seul label

merci de votre aide



Private Sub UserForm_Activate()
Dim Derligne%, Colonne%, Ligne%
Dim Compteur%, a
With Sheets('1')
On Error Resume Next
For Colonne = 4 To 4 '4 = la colonne 4 est à analyser
Compteur = 0
Derligne = .Cells(65536, Colonne).End(xlUp).Row
For Ligne = 1 To Derligne
a = UCase(.Cells(Ligne, Colonne).Value)

If UCase(.Cells(Ligne, Colonne).Value) = 'a' Then Compteur = Compteur + 1
If UCase(.Cells(Ligne, Colonne).Value) = 'b' Then Compteur = Compteur + 1
If UCase(.Cells(Ligne, Colonne).Value) = 'c' Then Compteur = Compteur + 1Then Compteur = Compteur + 1



Next
Me.Controls('TextBox' & Colonne - 2) = Compteur
Next
End With
End Sub
 

Robert

XLDnaute Barbatruc
Repose en paix
Bonjour Arvin, bonjour le forum,

Il te faut créer une variable compteur pour chaque lettre, une pour 'a' une pour 'b' et une pour 'c'. Ci-dessous avec la méthode Find :


Private Sub UserForm_Activate()
Dim a As Range, b As Range, c As Range
Dim ca As Integer, cb As Integer, cc As Integer
With Sheets('1').Range('D1:D' & Sheets('1').Range('D65536').End(xlUp).Row)
Set a = .Find('a', , xlValues)
If Not a Is Nothing Then
firstAddress = a.Address
Do
ca = ca + 1
Set a = .FindNext(a)
Loop While Not a Is Nothing And a.Address <> firstAddress
End If
MsgBox ca & ' a' 'place ca dans le textbox approprié
Set b = .Find('b', , xlValues)
If Not b Is Nothing Then
firstAddress = b.Address
Do
cb = cb + 1
Set b = .FindNext(b)
Loop While Not b Is Nothing And b.Address <> firstAddress
End If
MsgBox cb & ' b' 'place cb dans le textbox approprié
Set c = .Find('c', , xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
cc = cc + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
MsgBox cc & ' c' 'place cc dans le textbox approprié
End With
End Sub