Private Sub UserForm_Initialize()
With Me
.cbMod.List = Array("Modification Convoi", "Modification Horaire", "Modification Roulement", "Modification Parcours")
.obHD1.Value = True
End With
End Sub
Private Sub cmdHeures_Click()
Dim heure As Date
Dim col As Byte
Dim comp$, pre$
Dim i&
With Me
If Not IsDate(.tbHeure.Value) Then MsgBox "Inscrire l'horaire selon le format: hh:mm:ss": Exit Sub
heure = .tbHeure.Value
If .obHD1.Value Then
col = 7
Else
col = 14
End If
End With
With Sheets(3)
a = .Range("A2:T" & .Cells.Find("*", , , , xlByRows, xlPrevious).Row).Value
Select Case Me.cbPre.Value
Case False
a = FiltreArraySupLignesH(a, col, heure, "av")
Case True
a = FiltreArraySupLignesH(a, col, heure, "ap")
End Select
.Range("A2:T" & .Cells.Find("*", , , , xlByRows, xlPrevious).Row).ClearContents
.[A2].Resize(UBound(a), UBound(a, 2)).Formula = a
End With
End Sub
Private Sub cmdMod_Click()
Dim i&, tModif$, a()
With Me
If .cbMod.Value = "" Then Exit Sub
tModif = .cbMod.Value
End With
With Sheets(3)
a = .Range("A2:T" & .Cells.Find("*", , , , xlByRows, xlPrevious).Row).Value
a = FiltreArraySupLignesMod(a, 18, tModif)
.Range("A2:T" & .Cells.Find("*", , , , xlByRows, xlPrevious).Row).ClearContents
.[A2].Resize(UBound(a), UBound(a, 2)).Formula = a
End With
End Sub
Function FiltreArraySupLignesMod(Tbl, col, cle)
Dim i, n
Dim tmp(): ReDim tmp(1 To UBound(Tbl))
For i = LBound(Tbl) To UBound(Tbl)
If Tbl(i, col) <> cle Then n = n + 1: tmp(n) = i
Next
ReDim Preserve tmp(1 To n)
FiltreArraySupLignesMod = Application.Index(Tbl, Application.Transpose(tmp), _
Application.Transpose(Evaluate("Row(1:" & UBound(Tbl, 2) & ")")))
End Function
Function FiltreArraySupLignesH(Tbl, col, cle, pre)
Dim i, n
Dim tmp(): ReDim tmp(1 To UBound(Tbl))
Select Case pre
Case "av"
For i = LBound(Tbl) To UBound(Tbl)
If Tbl(i, col) >= cle Then n = n + 1: tmp(n) = i
Next i
Case "ap"
For i = LBound(Tbl) To UBound(Tbl)
If Tbl(i, col) <= cle Then n = n + 1: tmp(n) = i
Next i
End Select
ReDim Preserve tmp(1 To n)
FiltreArraySupLignesH = Application.Index(Tbl, Application.Transpose(tmp), _
Application.Transpose(Evaluate("Row(1:" & UBound(Tbl, 2) & ")")))
End Function