Option Base 1
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
' Nettoyage de la feuille Transfert
Application.EnableEvents = False
Me.Range(Me.Cells(4, 1), Me.Cells(65536, 15)).ClearContents
Dim i As Long
Dim FBanque As Worksheet
Set FBanque = Worksheets("Banque")
Dim TbdBanque As Variant
TbdBanque = FBanque.Range(FBanque.Cells(20, 1), FBanque.Cells(FBanque.Cells(65536, 1).End(xlUp).Row, 15))
' il suffit de remplire le tableau.
Dim TresBanque() As Variant
ReDim TresBanque(1)
If Not Application.Intersect(Target, Range("C1:C2")) Is Nothing Then
If Target.Count > 1 Then Exit Sub
If Sheets("Transfert").Range("C1") <> "" Then
For i = LBound(TbdBanque, 1) To UBound(TbdBanque, 1)
If Format(CDate(Me.Cells(1, 3)), "MMMM") = Format(CDate(TbdBanque(i, 2)), "MMMM") And Me.Cells(2, 3) = TbdBanque(i, 3) Then
'If CDate(Me.Cells(1, 3)) <= CDate(TbdBanque(i, 2)) And CDate(Me.Cells(1, 3)) < CDate(TbdBanque(i, 2)) And Me.Cells(2, 3) = TbdBanque(i, 3) Then
TresBanque(UBound(TresBanque)) = FBanque.Range(FBanque.Cells(i + 19, 1), FBanque.Cells(i + 19, 15))
ReDim Preserve TresBanque(UBound(TresBanque) + 1)
End If
Next i
'Else
'.Range("O1").ClearContents
End If
End If
' Evite le message d'erreur si la feuille n'existe pas.
On Error Resume Next
ReDim Preserve TresBanque(UBound(TresBanque) - 1)
For i = LBound(TresBanque, 1) To UBound(TresBanque, 1)
Me.Cells(i + 3, 1).Resize(UBound(TresBanque(i), 1), UBound(TresBanque(i), 2)) = TresBanque(i)
Next i
On Error GoTo 0
Application.EnableEvents = True
End Sub