Problème code affichage nb valeur suivant critère

Bonjour,

J'ai un petit soucis sur le code en gras, je voudrais que dans la TextBox2 de mon UserForm, il affichage la valeur suivante :

Sur la feuille "Amélioration", comptage du nombre de valeur dans la colonne D contenant le critère Application.UserName (il s'agit d'une variable qui dépend du pc sur lequel nous sommes connecté).

Quelqu'un peut - il m'aider à résoudre ce problème ?

Merci

Cdlt

Private Sub UserForm_Initialize()
TextBox1.Value = Application.UserName
TextBox8.Value = Format(Now, "DD/MM/YY")
With Sheets("Données globale")
TextBox6 = Sheets("Données globale").[B2]
TextBox5 = Sheets("Données globale").[A2]
TextBox7 = Sheets("Données globale").[C2]
End With

[b][u]With Sheets("Amélioration")
TextBox2 = Application.WorksheetFunction.CountIf(Range("D:D1048576"), Application.UserName)
End With
[/u][/b]
Label2.BackColor = RGB(64, 187, 180)
Label3.BackColor = RGB(64, 187, 180)
Label4.BackColor = RGB(64, 187, 180)
Label5.BackColor = RGB(64, 187, 180)
Label1.BackColor = RGB(64, 187, 180)

ComboBox2.AddItem "Oui"
ComboBox2.AddItem "Non"

DerLig = Sheets("Amélioration").Cells(Rows.Count, 7).End(xlUp).Row

For i = 2 To DerLig
    If Sheets("Amélioration").Cells(i, 3) = "En attente de validation" And Sheets("Amélioration").Cells(i, 4) = Application.UserName Then Me.ComboBox1.AddItem Sheets("Amélioration").Cells(i, 7)
Next

MsgBox ("Vous avez actuellement " & ComboBox1.ListCount & " actions en attente de validation")
End Sub

Bonsoir Floflo, bonsoir le forum,

Avec une instruction With il te faut un point (.) devant le Range :

With Sheets("Amélioration")

TextBox2 = Application.WorksheetFunction.CountIf(.Range("D:D1048576"), Application.UserName)

End With

Bonjour,

Essaie ainsi :

Option Explicit

Private Sub UserForm_Initialize()
Dim ws As Worksheet, ws2 As Worksheet
Dim User As String
Dim n As Long, I As Long
    Set ws = Worksheets("Données globale")
    Set ws2 = Worksheets("Amélioration")
    User = Application.UserName
    TextBox1.Value = User
    TextBox8.Value = Format(Date, "DD/MM/YY")
    With ws
        n = .Cells(.Rows.Count, 4).End(xlUp).Row
        TextBox2 = Application.CountIf(.Cells(1, 4).Resize(n), User)
        TextBox5 = .Cells(2, 1)
        TextBox6 = .Cells(2, 2)
        TextBox7 = .Cells(2, 3)
    End With
    Label2.BackColor = RGB(64, 187, 180)
    Label3.BackColor = RGB(64, 187, 180)
    Label4.BackColor = RGB(64, 187, 180)
    Label5.BackColor = RGB(64, 187, 180)
    Label1.BackColor = RGB(64, 187, 180)
    With ComboBox2
        .AddItem "Oui"
        .AddItem "Non"
    End With
    With ws2
        n = .Cells(Rows.Count, 7).End(xlUp).Row
        For I = 2 To n
            If .Cells(I, 3) = "En attente de validation" _
               And .Cells(I, 4) = User Then Me.ComboBox1.AddItem .Cells(I, 7)
        Next
    End With
    MsgBox ("Vous avez actuellement " & ComboBox1.ListCount & " actions en attente de validation.")
End Sub

Merci Eric !

C'est Nickel !

Bonjour, le fil, le forum,

J'ai prendre une douche moi !Je dois sentir le pâté...

Merci aussi Thauthème les deux fonctionnent

Re,

Ha ça va mieux... Après la douche...

Rechercher des sujets similaires à "probleme code affichage valeur suivant critere"