Microsoft 365 Compter date en fonction valeur tableau.

mld.sebastien

XLDnaute Junior
Bonjour,

J essaye de calculer le nombre de ticket pour le mois sous deux valeur. Mais je bug dessus mon code ce trouve utiliser dans la box_creation_evt userform initialisation.
 
Solution
il faut peut etre effacer la fiche avant de la remplir....
VB:
Private Sub Cmd_ImpressionFiche_Click()
    If Me.Cbx_NMR.ListIndex = -1 Then 'si il n'y a pas de selection OU qu'il y a une saisie ne correspondant pas à la liste du combo
        Me.Lbl_DateOuverture = ""
        Me.Lbl_DateModification = ""
        Me.Lbl_DateCloture = ""
        Me.Lbl_Description = ""
        Exit Sub
    End If
    
'*******************************
    'Controls de saisie
    If Me.Lbl_DateOuverture = "" Or Not IsDate(Me.Lbl_DateOuverture) Then 'on vérifie que il y a une date et qu'elle est valide
        'TxtDateCloture.BackColor = RGB(255, 0, 0)
        MsgBox "Merci Il y pas de date Ouverture"
        Lbl_DateOuverture.SetFocus
        Exit Sub...

vgendron

XLDnaute Barbatruc
désolé, mais je ne comprend strictement rien

le formulaire "Box_Recherche_EVT" fonctionne correctement

déjà. si tu mettais des données bidons mais facile à reconnaitre.. ce serait plus pratique
voir PJ
quand je selectionne une fiche, les données sont mises dans la feuille correctement...
(j'ai fait le test pour les 8 fiches)

si tu veux de l'aide, il faudrait déjà faire un effort pour écrire dans un Français compréhensible
 

Pièces jointes

  • EVT 2023.xlsm
    86.5 KB · Affichages: 1

mld.sebastien

XLDnaute Junior
Oui cela fonctionne bien certes, mais exemple je créer une fiche ensuite je la clôture pas de souci mais quand je la met via le formulaire "Box_Recherche_EVT" sur la fiche si y a déjà eu des info celle-ci reste dessus.

Exemple :
Je prend la fiche 1 ou tous est remplis dans le tableau, donc cela donne la copie écran fiche 1
Par contre je prend la fiche 8(ou j'ai supprimer les données modification dans le tableau) cela donne la copie écran fiche 8 mais dans celle-ci il y a les données de l'ancienne j'ai l'impression.
 

Pièces jointes

  • 1683218638046.png
    1683218638046.png
    39.9 KB · Affichages: 7
  • 1683218779311.png
    1683218779311.png
    39.8 KB · Affichages: 8
  • EVT 2023.xlsm
    88 KB · Affichages: 1

vgendron

XLDnaute Barbatruc
il faut peut etre effacer la fiche avant de la remplir....
VB:
Private Sub Cmd_ImpressionFiche_Click()
    If Me.Cbx_NMR.ListIndex = -1 Then 'si il n'y a pas de selection OU qu'il y a une saisie ne correspondant pas à la liste du combo
        Me.Lbl_DateOuverture = ""
        Me.Lbl_DateModification = ""
        Me.Lbl_DateCloture = ""
        Me.Lbl_Description = ""
        Exit Sub
    End If
    
'*******************************
    'Controls de saisie
    If Me.Lbl_DateOuverture = "" Or Not IsDate(Me.Lbl_DateOuverture) Then 'on vérifie que il y a une date et qu'elle est valide
        'TxtDateCloture.BackColor = RGB(255, 0, 0)
        MsgBox "Merci Il y pas de date Ouverture"
        Lbl_DateOuverture.SetFocus
        Exit Sub
    End If

'*******************************
    ResetFiche
    With Sheets("EVT-MUSE") 'avec la feuille
        '.Activate 'on l'active
        
        With .ListObjects("t_EvtMuse") 'avec la table
            Set trouve = .ListColumns("NMR").Range.Find(Me.Cbx_NMR, lookat:=xlWhole) 'on cherche le NMR dans la colonne
            If Not trouve Is Nothing Then 'si on l'a trouvé
                'trouve.Select 'on selectionne le NMR (aucun intérêt autre que visuel)
                Ligne = trouve.Row - .Range.Row 'numéro de ligne
                
                If IsDate(Lbl_DateOuverture) Then Sheets("Fiche Suivi Incident").Range("F9").Value = CDate(.ListColumns(2).DataBodyRange(Ligne)) Else Me.Lbl_DateOuverture = "" 'Date Ouverture
                If IsDate(Lbl_DateCloture) Then Sheets("Fiche Suivi Incident").Range("F10").Value = CDate(.ListColumns(18).DataBodyRange(Ligne)) Else Me.Lbl_DateCloture = "" 'Date Cloture
                
                Sheets("Fiche Suivi Incident").Range("D1").Value = .ListColumns(1).DataBodyRange(Ligne) ' NMR
                Sheets("Fiche Suivi Incident").Range("F5").Value = .ListColumns(5).DataBodyRange(Ligne) 'Référence
                Sheets("Fiche Suivi Incident").Range("C5").Value = .ListColumns(11).DataBodyRange(Ligne) 'Site concerné
                Sheets("Fiche Suivi Incident").Range("C7").Value = .ListColumns(12).DataBodyRange(Ligne) 'Contact
                Sheets("Fiche Suivi Incident").Range("D9").Value = .ListColumns(13).DataBodyRange(Ligne) 'N° de Tel
                Sheets("Fiche Suivi Incident").Range("B10").Value = .ListColumns(14).DataBodyRange(Ligne) 'Serveur SM
                Sheets("Fiche Suivi Incident").Range("B11").Value = .ListColumns(15).DataBodyRange(Ligne) 'Serveur PMF
                Sheets("Fiche Suivi Incident").Range("B12").Value = .ListColumns(16).DataBodyRange(Ligne) 'Bureau Courrier
                Sheets("Fiche Suivi Incident").Range("A15").Value = .ListColumns(6).DataBodyRange(Ligne) 'Description Succinte
                Sheets("Fiche Suivi Incident").Range("D22").Value = .ListColumns(7).DataBodyRange(Ligne) 'Description
                
                If IsDate(Lbl_DateOuverture) Then Sheets("Fiche Suivi Incident").Range("A22").Value = CDate(.ListColumns(2).DataBodyRange(Ligne)) Else Me.Lbl_DateOuverture = "" 'Date Ouverture
                Sheets("Fiche Suivi Incident").Range("B22").Value = .ListColumns(3).DataBodyRange(Ligne) 'Trigramme Ouverture

                If IsDate(Lbl_DateModification) Then Sheets("Fiche Suivi Incident").Range("A23").Value = CDate(.ListColumns(8).DataBodyRange(Ligne)) Else Me.Lbl_DateModification = "" ' Date Modification
                Sheets("Fiche Suivi Incident").Range("B23").Value = .ListColumns(9).DataBodyRange(Ligne) 'Trigramme Modification
                Sheets("Fiche Suivi Incident").Range("D23").Value = .ListColumns(10).DataBodyRange(Ligne) 'Description Modification

                If IsDate(Lbl_DateCloture) Then Sheets("Fiche Suivi Incident").Range("A24").Value = CDate(.ListColumns(18).DataBodyRange(Ligne)) Else Me.Lbl_DateCloture = "" ' Date Cloture
                Sheets("Fiche Suivi Incident").Range("B24").Value = .ListColumns(19).DataBodyRange(Ligne) 'Trigramme Cloture
                Sheets("Fiche Suivi Incident").Range("D24").Value = .ListColumns(20).DataBodyRange(Ligne) 'Description Cloture
            End If
        End With
    End With
    
    MsgBox "La recherche a été prise en compte."
    
    Lbl_Description = ""
    Me.Lbl_DateOuverture = ""
    Me.Lbl_DateCloture = ""
    Me.Lbl_Description = ""
    UserForm_Initialize 'on rappelle l'intialize pour mettre à jour le Combo
End Sub

Sub ResetFiche()
    With Sheets("Fiche Suivi Incident")
        .Range("F9").Value = ""
        .Range("F10").Value = ""
    
        .Range("D1").Value = "" ' NMR
        .Range("F5").Value = "" 'Référence
        .Range("C5").Value = "" 'Site concerné
        .Range("C7").Value = "" 'Contact
        .Range("D9").Value = "" 'N° de Tel
        .Range("B10").Value = "" 'Serveur SM
        .Range("B11").Value = "" 'Serveur PMF
        .Range("B12").Value = "" 'Bureau Courrier
        .Range("A15").Value = "" 'Description Succinte
        .Range("D22").Value = "" 'Description
    
        .Range("A22").Value = ""  'Date Ouverture
        .Range("B22").Value = "" 'Trigramme Ouverture
    
        .Range("A23").Value = ""  ' Date Modification
        .Range("B23").Value = "" 'Trigramme Modification
        .Range("D23").Value = "" 'Description Modification
    
        .Range("A24").Value = ""  ' Date Cloture
        .Range("B24").Value = "" 'Trigramme Cloture
        .Range("D24").Value = "" 'Description Cloture
    End With
End Sub
 

mld.sebastien

XLDnaute Junior
il faut peut etre effacer la fiche avant de la remplir....
VB:
Private Sub Cmd_ImpressionFiche_Click()
    If Me.Cbx_NMR.ListIndex = -1 Then 'si il n'y a pas de selection OU qu'il y a une saisie ne correspondant pas à la liste du combo
        Me.Lbl_DateOuverture = ""
        Me.Lbl_DateModification = ""
        Me.Lbl_DateCloture = ""
        Me.Lbl_Description = ""
        Exit Sub
    End If
   
'*******************************
    'Controls de saisie
    If Me.Lbl_DateOuverture = "" Or Not IsDate(Me.Lbl_DateOuverture) Then 'on vérifie que il y a une date et qu'elle est valide
        'TxtDateCloture.BackColor = RGB(255, 0, 0)
        MsgBox "Merci Il y pas de date Ouverture"
        Lbl_DateOuverture.SetFocus
        Exit Sub
    End If

'*******************************
    ResetFiche
    With Sheets("EVT-MUSE") 'avec la feuille
        '.Activate 'on l'active
       
        With .ListObjects("t_EvtMuse") 'avec la table
            Set trouve = .ListColumns("NMR").Range.Find(Me.Cbx_NMR, lookat:=xlWhole) 'on cherche le NMR dans la colonne
            If Not trouve Is Nothing Then 'si on l'a trouvé
                'trouve.Select 'on selectionne le NMR (aucun intérêt autre que visuel)
                Ligne = trouve.Row - .Range.Row 'numéro de ligne
               
                If IsDate(Lbl_DateOuverture) Then Sheets("Fiche Suivi Incident").Range("F9").Value = CDate(.ListColumns(2).DataBodyRange(Ligne)) Else Me.Lbl_DateOuverture = "" 'Date Ouverture
                If IsDate(Lbl_DateCloture) Then Sheets("Fiche Suivi Incident").Range("F10").Value = CDate(.ListColumns(18).DataBodyRange(Ligne)) Else Me.Lbl_DateCloture = "" 'Date Cloture
               
                Sheets("Fiche Suivi Incident").Range("D1").Value = .ListColumns(1).DataBodyRange(Ligne) ' NMR
                Sheets("Fiche Suivi Incident").Range("F5").Value = .ListColumns(5).DataBodyRange(Ligne) 'Référence
                Sheets("Fiche Suivi Incident").Range("C5").Value = .ListColumns(11).DataBodyRange(Ligne) 'Site concerné
                Sheets("Fiche Suivi Incident").Range("C7").Value = .ListColumns(12).DataBodyRange(Ligne) 'Contact
                Sheets("Fiche Suivi Incident").Range("D9").Value = .ListColumns(13).DataBodyRange(Ligne) 'N° de Tel
                Sheets("Fiche Suivi Incident").Range("B10").Value = .ListColumns(14).DataBodyRange(Ligne) 'Serveur SM
                Sheets("Fiche Suivi Incident").Range("B11").Value = .ListColumns(15).DataBodyRange(Ligne) 'Serveur PMF
                Sheets("Fiche Suivi Incident").Range("B12").Value = .ListColumns(16).DataBodyRange(Ligne) 'Bureau Courrier
                Sheets("Fiche Suivi Incident").Range("A15").Value = .ListColumns(6).DataBodyRange(Ligne) 'Description Succinte
                Sheets("Fiche Suivi Incident").Range("D22").Value = .ListColumns(7).DataBodyRange(Ligne) 'Description
               
                If IsDate(Lbl_DateOuverture) Then Sheets("Fiche Suivi Incident").Range("A22").Value = CDate(.ListColumns(2).DataBodyRange(Ligne)) Else Me.Lbl_DateOuverture = "" 'Date Ouverture
                Sheets("Fiche Suivi Incident").Range("B22").Value = .ListColumns(3).DataBodyRange(Ligne) 'Trigramme Ouverture

                If IsDate(Lbl_DateModification) Then Sheets("Fiche Suivi Incident").Range("A23").Value = CDate(.ListColumns(8).DataBodyRange(Ligne)) Else Me.Lbl_DateModification = "" ' Date Modification
                Sheets("Fiche Suivi Incident").Range("B23").Value = .ListColumns(9).DataBodyRange(Ligne) 'Trigramme Modification
                Sheets("Fiche Suivi Incident").Range("D23").Value = .ListColumns(10).DataBodyRange(Ligne) 'Description Modification

                If IsDate(Lbl_DateCloture) Then Sheets("Fiche Suivi Incident").Range("A24").Value = CDate(.ListColumns(18).DataBodyRange(Ligne)) Else Me.Lbl_DateCloture = "" ' Date Cloture
                Sheets("Fiche Suivi Incident").Range("B24").Value = .ListColumns(19).DataBodyRange(Ligne) 'Trigramme Cloture
                Sheets("Fiche Suivi Incident").Range("D24").Value = .ListColumns(20).DataBodyRange(Ligne) 'Description Cloture
            End If
        End With
    End With
   
    MsgBox "La recherche a été prise en compte."
   
    Lbl_Description = ""
    Me.Lbl_DateOuverture = ""
    Me.Lbl_DateCloture = ""
    Me.Lbl_Description = ""
    UserForm_Initialize 'on rappelle l'intialize pour mettre à jour le Combo
End Sub

Sub ResetFiche()
    With Sheets("Fiche Suivi Incident")
        .Range("F9").Value = ""
        .Range("F10").Value = ""
   
        .Range("D1").Value = "" ' NMR
        .Range("F5").Value = "" 'Référence
        .Range("C5").Value = "" 'Site concerné
        .Range("C7").Value = "" 'Contact
        .Range("D9").Value = "" 'N° de Tel
        .Range("B10").Value = "" 'Serveur SM
        .Range("B11").Value = "" 'Serveur PMF
        .Range("B12").Value = "" 'Bureau Courrier
        .Range("A15").Value = "" 'Description Succinte
        .Range("D22").Value = "" 'Description
   
        .Range("A22").Value = ""  'Date Ouverture
        .Range("B22").Value = "" 'Trigramme Ouverture
   
        .Range("A23").Value = ""  ' Date Modification
        .Range("B23").Value = "" 'Trigramme Modification
        .Range("D23").Value = "" 'Description Modification
   
        .Range("A24").Value = ""  ' Date Cloture
        .Range("B24").Value = "" 'Trigramme Cloture
        .Range("D24").Value = "" 'Description Cloture
    End With
End Sub
Oui c'est cela, excuse moi si pas très explicite.
 

mld.sebastien

XLDnaute Junior
Super si bien compris j'ai revu un autre code ça donne cela, peu être à mieux ranger ??

VB:
Sub Mensuel()
'Détermination des variables

Dim NBR_COURS_mois As Integer
Dim NBR_CLOS_mois As Integer
Dim Mensuel As String

Sheets("EVT-MUSE").Activate

Periode_mois = Month(CDate("01/" & Sheets("Préface").Range("E13")))
'Sheets("Préface").Range("C7") = Periode_mois
Periode_Année = Year(CDate("01/01/" & Sheets("Préface").Range("E12")))
'Sheets("Préface").Range("C8") = Periode_Année

Mensuel = Format(Periode_mois & "/" & Periode_Année, "mm/yyyy")
'Sheets("Préface").Range("C9") = Mensuel

    If Mensuel = "" Then 'on fait le test AVANT la boucle == pas la peine de le faire à chaque fois
        MsgBox "La date de fin saisie est avant la date de début." & vbCrLf & " Veuillez saisir des bonnes valeurs!!", vbInformation + vbOKOnly, "INFORMATION"
        Exit Sub
    End If
    'initialisation des compteurs
    NBR_CLOS_mois = 0
    NBR_COURS_mois = 0

    With Sheets("EVT-MUSE").ListObjects("t_EvtMuse") 'avec la table "t_EvtMuse" de la feuille
        For i = 1 To .ListRows.Count 'pour chaque ligne
            Date_Ouverture = Format(.ListColumns("Date Ouverture").DataBodyRange(i), "mm/yyyy")
            If Date_Ouverture >= Mensuel And Date_Ouverture <= Mensuel Then 'si la date est dans la période
                Select Case .ListColumns("Statut").DataBodyRange(i) 'selon le statut
                    Case "Clos"
                        NBR_CLOS_mois = NBR_CLOS_mois + 1
                    Case "En cours"
                        NBR_COURS_mois = NBR_COURS_mois + 1
                End Select
            End If
        Next i
        'mise à jour des résultats dans la feuille
        Sheets("Préface").Range("I13") = NBR_CLOS_mois
        Sheets("Préface").Range("H13") = NBR_COURS_mois
        Sheets("Préface").Range("G13") = NBR_CLOS_mois + NBR_COURS_mois
        Sheets("Préface").Select
    End With
End Sub
 

Discussions similaires