Derlign macro non fonctionnel

Bonsoir,

J'essaye d'effectuer une macro simple qui compte simplement les jours qui sont passés en mois

Elle se trouve dans le module 5 si besoin mais je vous la mets ici aussi

Mon idée c'est d'afficher dans un msgbox le nombre d'annulation dans le mois

Merci d'avance

Sub comptage()

Dim nb As Integer

Dim I As Integer

Dim Z As Integer

Dim Y As Integer

Dim W As Integer

Dim v As Integer

With Worksheets("Seminaire annulé")

Dim DerLigne As Long

DerLigne = .Range("A65536").End(xlUp).Row

Z = 0

Y = 0

W = 0

v = 0

For I = DerLigne To 2 Step -1

If Month(.Cells(I, "A").Value) = Month(7 / 1 / 2018) Then Z = Z + 1

If Month(.Cells(I, "A").Value) = Month(8 / 1 / 2018) Then Y = Y + 1

If Month(.Cells(I, "A").Value) = Month(9 / 1 / 2018) Then W = W + 1

If Month(.Cells(I, "A").Value) = Month(10 / 1 / 2018) Then v = v + 1

Next I

If Z <> 0 Then MsgBox ("il y a eu " & Z & " annulation le mois de juillet") Else

If Y <> 0 Then MsgBox ("il y a eu " & Y & " annulation le mois d'aout") Else

If W <> 0 Then MsgBox ("il y a eu " & W & " annulation le mois de septembre") Else

If v <> 0 Then MsgBox ("il y a eu " & v & " annulation le mois d'octobre")

End With

End Sub

Bonjour,

Et comme ceci ...

If Month(.Cells(I, "A").Value) = Month("7/1/2018") Then Z = Z + 1

ric

Malheureusement ça ne change rien..

Bonjour,

Et comme ceci :

Sub comptage()
Dim nb As Integer
Dim I, Z, Y, W, V As Integer
Dim DerLigne As Long

With Worksheets("Seminaire annulé")
    DerLigne = .Range("A65536").End(xlUp).Row
    Z = 0
    Y = 0
    W = 0
    V = 0

    For I = DerLigne To 2 Step -1
        If Month(.Cells(I, "A").Value) = Month("7/1/2018") Then Z = Z + 1
        If Month(.Cells(I, "A").Value) = Month("8/1/2018") Then Y = Y + 1
        If Month(.Cells(I, "A").Value) = Month("9/1/2018") Then W = W + 1
        If Month(.Cells(I, "A").Value) = Month("10/1/2018") Then V = V + 1
    Next I

    If Z <> 0 Then MsgBox ("il y a eu " & Z & " annulation le mois de juillet") Else
    If Y <> 0 Then MsgBox ("il y a eu " & Y & " annulation le mois d'aout") Else
    If W <> 0 Then MsgBox ("il y a eu " & W & " annulation le mois de septembre") Else
    If V <> 0 Then MsgBox ("il y a eu " & V & " annulation le mois d'octobre")
End With
End Sub

ric

Bonsoir,

ci-dessous autre proposition de code

    Dim DerLigne As Long
    Dim mois_annulations As Object
    Dim année As Integer, mois_annul As Integer, mois As Variant

    'stockage nombre d'annulation du mois dans collection de type dictionnaire
    With Sheets("Seminaire annul?")
        DerLigne = .Cells(Rows.Count, "A").End(xlUp).Row
        Set mois_annulations = CreateObject("Scripting.Dictionary")
        For I = 2 To DerLigne
            mois = Year(.Cells(I, "A")) & "." & Month(.Cells(I, "A"))
            mois_annulations(mois) = Val(mois_annulations(mois)) + 1
        Next I
    End With

    'affichage nombre d'annulations pour chaque mois
    For Each mois In mois_annulations.keys
        année = Split(mois, ".")(0): mois_annul = Split(mois, ".")(1)
        MsgBox "annulations mois " & Format(DateSerial(année, mois_annul, 1), "mmm yyyy") & " = " & mois_annulations(mois)
    Next mois

Bonjour,

Une autre approche :

Sub comptage()
Dim DerLigne As Long, I As Long
Dim z As Double, y As Double, w As Double, v As Double
    With Worksheets("Seminaire annul?")
        DerLigne = .Cells(.Rows.Count, 1).End(xlUp).Row
        For I = 2 To DerLigne
            Select Case Month(.Cells(I, 1))
                Case 7: z = z + 1
                Case 8: y = y + 1
                Case 9: w = w + 1
                Case 10: v = v + 1
                Case Else:
            End Select
        Next I
        If z > 0 Then MsgBox ("il y a eu " & z & " annulation(s) au mois de juillet")
        If y > 0 Then MsgBox ("il y a eu " & y & " annulation(s) au mois d'ao?t")
        If w > 0 Then MsgBox ("il y a eu " & w & " annulation(s) au mois de septembre")
        If v > 0 Then MsgBox ("il y a eu " & v & " annulation(s) au mois d'octobre")
    End With
End Sub

Bonjour

mettre DateSerial(an,mois,jour)

ex : If Month(.Cells(I, 1).Value) = Month(DateSerial(2018, 5, 1)) Then Z = Z + 1

A+

Maurice

Ce code répond parfaitement à mes attentes, merci beaucoup de votre aide à tous

Rechercher des sujets similaires à "derlign macro fonctionnel"