
Function CopyDataFromListViewToSheet()
Dim ws As Worksheet
Dim i As Integer, j As Integer
Dim ligne As Integer

Set ws = ThisWorkbook.Sheets("Releve")
ligne = 4

With ws
    For i = 1 To ListView1.ListItems.Count
        .Cells(ligne, 1).Value = Format(ListView1.ListItems(i).Text, "mm/dd/yyyy")

        For j = 2 - 1 To 6 - 1
            With ListView1.ListItems(i)
                If IsNumeric(.SubItems(j)) Then
                    ws.Cells(ligne, j + 1).Value = CDbl(.SubItems(j))
                    Else: ws.Cells(ligne, j + 1).Value = .SubItems(j)
                End If
            End With
        Next j
        ligne = ligne + 1
    Next i
End With
End Function

Function Chercher_Entre_Deux_Dates_Dans_listview()
Dim c As Range
Dim f As Worksheet

ListView1.ListItems.Clear
Set f = ThisWorkbook.Worksheets(ComboBox1.Value)

With f
  For Each c In .Range(.Cells(4, 1), .Cells(.Cells(Rows.Count, 1).End(xlUp).Row, 6))
    If IsDate(c) Then
      If CDate(c) >= (Me.TextBox3.Value) And CDate(c) <= (Me.TextBox4.Value) Then
          With Me.ListView1
            .ListItems.Add , , c
              .ListItems(.ListItems.Count).ListSubItems.Add , , c.Offset(0, 1)
              .ListItems(.ListItems.Count).ListSubItems.Add , , c.Offset(0, 2)
              .ListItems(.ListItems.Count).ListSubItems.Add , , c.Offset(0, 3)
              .ListItems(.ListItems.Count).ListSubItems.Add , , c.Offset(0, 4)
              .ListItems(.ListItems.Count).ListSubItems.Add , , c.Offset(0, 5)
          End With
      End If
    End If
  Next c
End With
End Function

Private Sub ComboBox1_Change()
Dim Min As Date, Max As Date
Dim f As Worksheet
Dim lastrow As Integer

ListView1.ListItems.Clear
If ComboBox1.Value = vbNullString Then Exit Sub

Set f = Worksheets(ComboBox1.Value)
lastrow = f.Range("A" & Rows.Count).End(xlUp).Row

With f
    TextBox1 = Format(CDate(.Range("L1")), "dd/mm/yyyy")
    TextBox2 = Format(CDate(.Range("L2")), "dd/mm/yyyy")

    .Range("L1").FormulaR1C1 = "=MIN(R[3]C[-11]:R[" & lastrow & "]C[-11])"
    .Range("L2").FormulaR1C1 = "=MAX(R[2]C[-11]:R[" & lastrow & "]C[-11])"
End With

Call ListViewFil(f, lastrow)
End Sub

Private Sub CommandButton1_Click()
Dim i As Integer
Dim lastline As Integer

With Sheets("Releve")
    lastline = .Cells(Rows.Count, "A").End(xlUp).Row
    .Range("A4:F" & lastline).Clear
    .Range("B1:B2").Clear
    .Range("A1:A2") = "Releve de la feuille" & Worksheets(ComboBox1.Value).Name

    .Range("B1") = CDate(Me.TextBox3.Value)
    .Range("B2") = CDate(Me.TextBox4.Value)
End With

Chercher_Entre_Deux_Dates_Dans_listview
CopyDataFromListViewToSheet

Sheets("Releve").Activate
'Call Module1.FusionnerA1_A2 'Dan - désactivée car code absent dans module 1
End Sub

Sub ListViewFil(f As Worksheet, lastrow As Integer)
Dim r As Integer, c As Integer
Dim li As Object

For r = 4 To lastrow
    Set li = ListView1.ListItems.Add(, , f.Cells(r, 1))
    For c = 2 To 6
        li.ListSubItems.Add , , f.Cells(r, c)
    Next c
Next r
End Sub

Private Sub textbox2_AfterUpdate()
On Error Resume Next
Me.TextBox2 = Format(CDate(Me.TextBox2), "dd/mm/yyyy")
End Sub

Private Sub TextBox3_AfterUpdate()

Me.TextBox3 = Format(CDate(Me.TextBox3), "dd/mm/yyyy")
End Sub

Private Sub Textbox4_AfterUpdate()

With Me
    If .TextBox3.Value = "" Then
        MsgBox "Veuillez d'abord saisir une Date Debut", vbCritical, "Saisir Date": Exit Sub
    End If
End With

With TextBox4
    .Value = Format(CDate(Me.TextBox4), "dd/mm/yyyy")
    If CLng(CDate(.Value)) < CLng(CDate(TextBox1)) Then
        MsgBox "La date de fin du relevé doit être comprise entre le " & vbCrLf & _
            TextBox1.Value & " et le " & TextBox2.Value, vbCritical, "Date incorrecte"
        TextBox4 = vbNullString
    End If
End With

End Sub

Private Sub UserForm_Initialize()
Dim i As Byte

With Me
    .Label1.Caption = "Choix" + vbCrLf + "Base"
    .Label2.Caption = "Relevé" + vbCrLf + "Date Début:"
    .Label3.Caption = "Relevé" + vbCrLf + "Date Fin:"
    .Label4.Caption = "Date Début >=" + vbCrLf + " Date MIN:"
    .Label5.Caption = "Date Fin <=" + vbCrLf + "Date MAX:"

    For i = 1 To Sheets.Count
      .ComboBox1.AddItem Sheets(i).Name
    Next i
End With

With ListView1
    .View = lvwReport
    .CheckBoxes = False
    .FullRowSelect = True
    .Gridlines = True
    With .ColumnHeaders
       .Clear
       .Add , , "Date", 50
       .Add , , "Ctegorie", 60
       .Add , , "Libelle", 260
       .Add , , "Debit", 60
       .Add , , "Credit", 60
       .Add , , "Solde", 60
    End With
End With
End Sub