1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| Option Explicit
Private Sub ComboBox1_Change()
Dim Cpt As Integer
Dim IndexMin As Double, IndexMax As Double
Dim IndexMinOk As Boolean, IndexMaxOk As Boolean
IndexMinOk = False
IndexMaxOk = False
For Cpt = 2 To Range("A65536").End(xlUp).Row
If Month(Range("A" & Cpt).Value) = Me.ComboBox1.ListIndex + 1 Then
If Not IndexMinOk Then
IndexMin = Range("B" & Cpt).Value
IndexMinOk = True
Else
IndexMax = Range("B" & Cpt).Value
IndexMaxOk = True
End If
End If
Next Cpt
If IndexMinOk And IndexMaxOk Then
Me.TextBox1.Value = IndexMax - IndexMin
Else
Me.TextBox1.Value = 0
End If
End Sub
Private Sub UserForm_Initialize()
Me.ComboBox1.List = Array("Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre")
Me.ComboBox1.ListIndex = Month(Date) - 1
End Sub |
Partager