Autres compter

mohaamri

XLDnaute Nouveau
Bonsoir amis
dans mon exemple je veux savoir combien de jour "p" et jour"a" dans textbox1 ET2 aprés choix intervalle date
grand merci
 

Pièces jointes

  • Classeur1.xlsm
    16.9 KB · Affichages: 24

job75

XLDnaute Barbatruc
Bonsoir mohaamri, chezswan,

Voyez le fichier joint et le code de l'UserForm :
VB:
Private Sub ComboBox1_Change()
Dim deb As Date, fin As Date, tablo, i&, x, y$, n1&, n2&
TextBox1 = "": TextBox2 = ""
If Not IsDate(ComboBox1) Or Not IsDate(ComboBox2) Then Exit Sub
deb = Application.Min(CDate(ComboBox1), CDate(ComboBox2))
fin = Application.Max(CDate(ComboBox1), CDate(ComboBox2))
tablo = Feuil1.[A1].CurrentRegion.Resize(, 2) 'matrice, plus rapide
For i = 2 To UBound(tablo)
    x = tablo(i, 1)
    If x >= deb And x <= fin Then
        y = LCase(tablo(i, 2))
        If y = "p" Then n1 = n1 + 1
        If y = "a" Then n2 = n2 + 1
    End If
Next
TextBox1 = n1: TextBox2 = n2
End Sub

Private Sub ComboBox2_Change()
ComboBox1_Change
End Sub

Private Sub UserForm_Initialize()
With Feuil1.[A1].CurrentRegion.Resize(, 2)
    If .Rows.Count > 1 Then ComboBox1.List = .Rows(2).Resize(.Rows.Count - 1).Value: _
        ComboBox2.List = ComboBox1.List
End With
End Sub
A+
 

Pièces jointes

  • Classeur(1).xlsm
    22.1 KB · Affichages: 5

Discussions similaires

Statistiques des forums

Discussions
312 294
Messages
2 086 902
Membres
103 404
dernier inscrit
sultan87