Recherche et comptage de valeur par date

Bonjour j'ai un soucis, je cherche à compter le nombre de fois que ce repète le mot ON dans un classeur en fonction de la date saisie mais je n'y arrive pas.

Private Sub productionacejour_Click()

Private Sub productiondatex_Click()
Dim Ws As Worksheet
Dim Mot1 As String
Dim Mot2 As String
Dim Depart As String
Dim LaDate As Date
Dim Compteur As Integer
Dim Cel As Range

  Mot1 = InputBox("Entrer la date recherchée au format JJ/MM/AAAA", "titre")
  LaDate = CDate(Mot1)

  Mot2 = "---- ON ----"

  For Each Ws In Sheets
    With Ws.Cells
      Set Cel = .Find(what:=LaDate, LookIn:=xlValues, lookat:=xlWhole)
      If Not Cel Is Nothing Then
        Depart = Cel.Address
        Do
          If InStr(1, Cel.Offset(0, 1), Mot2) > 0 Then
            Compteur = Compteur + 1
          End If
          Set Cel = .FindNext(Cel)
        Loop While Depart <> Cel.Address
      End If
    End With
  Next Ws
  If Compteur > 0 Then
    MsgBox "La Production du " & Mot1 & " est de " & Compteur & " produit(s)"
  Else
    MsgBox "Aucune production le " & Mot1
  End If
End Sub

Cordialement

18exemple.xlsm (34.82 Ko)

Bonjour

Mets cette macro dans le code de ton bouton

Private Sub productiondatex_Click()
Dim Ws As Worksheet
Dim Mot1 As String
Dim Mot2 As String
Dim Depart As String
Dim Compteur As Integer
Dim Cel As Range

  Mot1 = InputBox("Entrer la date recherchée au format JJ/MM/AAAA", "titre")

  If Mot1 = "" Then Exit Sub

  Mot2 = "---- ON ----"

  For Each Ws In Sheets
    If Ws.Name <> "Menu" Then
      With Ws.Cells
        Set Cel = .Find(what:=Mot1, LookIn:=xlValues, lookat:=xlPart)
        If Not Cel Is Nothing Then
          Depart = Cel.Address
          Do
            If InStr(1, Cel, Mot2) > 0 Then
              Compteur = Compteur + 1
            End If
            Set Cel = .FindNext(Cel)
          Loop While Depart <> Cel.Address
        End If
      End With
    End If
  Next Ws
  If Compteur > 0 Then
    MsgBox "La Production du " & Mot1 & " est de " & Compteur & " produit(s)"
  Else
    MsgBox "Aucune production le " & Mot1
  End If
End Sub

Bonjour

Merci ça marche bien

Cordialement

Rechercher des sujets similaires à "recherche comptage valeur date"