XL 2016 filtrer les dates entre deux dates spécifiques

BalighTomy

XLDnaute Nouveau
salut
Dans userform1
C.UsedRange.AutoFilter 1, ">=" & Me.TextBox1.Value, xlAnd, "<=" & Me.TextBox2.Value
le filtre entre deux dates ne fonctionne pas . merci d'avance
 

Pièces jointes

  • en cours.xlsm
    42.5 KB · Affichages: 8

job75

XLDnaute Barbatruc
Bonsoir à tous,

Il faut en effet convertir les dates en nombres comme le fait TooFatBoy ou comme ceci :
VB:
c.UsedRange.AutoFilter 1, ">=" & CLng(CDate(TextBox1)), xlAnd, "<=" & CLng(CDate(TextBox2))
Il faut s'assurer auparavant que les TextBox contiennent bien des dates.

A+
 

ChTi160

XLDnaute Barbatruc
Bonjour le Fil
Ou avec cette version :
VB:
c.UsedRange.AutoFilter 1, ">=" & CLng(DateValue(Me.TextBox1.Value)), xlAnd, "<=" & CLng(DateValue(Me.TextBox2.Value))
x.Cells.ClearContents
c.UsedRange.SpecialCells(xlCellTypeVisible).Copy 'Ici aussi j'ai modifié
Bonne Journée
Jean marie
 

BalighTomy

XLDnaute Nouveau
salut tout le monde
même problème . voila j'ai utilisé la méthode simple .
VB:
Option Explicit
Private Sub CommandButton1_Click()
Frame1.Visible = True
ListBox1.Visible = False
End Sub
Private Sub CommandButton2_Click()
Frame2.Visible = True
ListBox1.Visible = False
End Sub
Private Sub CommandButton3_Click()
'Dim c As Worksheet
'Set c = ThisWorkbook.Sheets("source")
'Dim x As Worksheet
'Set x = ThisWorkbook.Sheets("filtre")

'c.UsedRange.AutoFilter 1, ">=" & Me.TextBox1.Value, xlAnd, "<=" & Me.TextBox2.Value
'c.UsedRange.AutoFilter 1, ">=" & CLng(CDate(TextBox1)), xlAnd, "<=" & CLng(CDate(TextBox2))
'c.UsedRange.AutoFilter 1, ">=" & 1 * CDate(Me.TextBox1.Value), xlAnd, "<=" & 1 * CDate(Me.TextBox2.Value)
'c.UsedRange.AutoFilter 1, ">=" & CLng(DateValue(Me.TextBox1.Value)), xlAnd, "<=" & CLng(DateValue(Me.TextBox2.Value))
'x.Cells.ClearContents
'c.UsedRange.SpecialCells(xlCellTypeVisible).Copy 'Ici aussi j'ai modifié
'x.Cells.ClearContents
'c.UsedRange.Copy

'x.Range("a1").PasteSpecial xlPasteValues
'x.Range("a1").PasteSpecial xlPasteFormats

'c.AutoFilterMode = False
'Dim last_row As Long
'last_row = Application.WorksheetFunction.CountA(x.Range("A:A"))

'If last_row = 1 Then last_row = 2
'With Me.ListBox1
'.ColumnHeads = True
'.ColumnCount = 10
'.ColumnWidths = "50"
'.RowSource = x.Name & "!a2:j" & last_row
'End With
Call search_between_two_dates_in_listbox
ListBox1.Visible = True
End Sub
Function search_between_two_dates_in_listbox()
Dim i As Integer
Dim j As Integer
Dim ListCount1 As Integer
ListCount1 = ListBox1.ListCount - 1
If TextBox1 <> "" Then
For i = ListCount1 To 0 Step -1
If (ListBox1.list(i, 0) < CDate(TextBox1)) Then
ListBox1.RemoveItem (i)
End If
Next i
End If
ListCount1 = ListBox1.ListCount - 1
If TextBox2 <> "" Then
For j = ListCount1 To 0 Step -1
If (ListBox1.list(j, 0) > CDate(TextBox2)) Then
ListBox1.RemoveItem (j)
End If
Next j
End If
End Function
Function format_columns_in_listbox()
Dim i As Integer
For i = 0 To ListBox1.ListCount - 1
ListBox1.list(i, 1) = (Format(ListBox1.list(i, 1), "dd.mm.yyyy"))
Next
End Function
Function show_data_in_listbox()
ListBox1.ColumnCount = 10
ListBox1.ColumnWidths = "50;50;50;50;50;50;50;50;50;50"
Sheets("source").Activate
Dim lastrow As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
ListBox1.list = Range("A2:J" & lastrow).Value
End Function
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
Me.TextBox1 = MonthView1
Frame1.Visible = False
End Sub
Private Sub MonthView2_DateClick(ByVal DateClicked As Date)
Me.TextBox2 = MonthView2
Frame2.Visible = False
End Sub
Private Sub Textbox1_AfterUpdate()
On Error Resume Next
Me.TextBox1 = Format(CDate(Me.TextBox1), "dd mmm yyyy")
End Sub
Private Sub Textbox2_AfterUpdate()
On Error Resume Next
Me.TextBox2 = Format(CDate(Me.TextBox2), "dd mmm yyyy")
End Sub
Private Sub UserForm_Initialize()
Call show_data_in_listbox
Call format_columns_in_listbox
Frame1.Visible = False
Frame2.Visible = False
End Sub
 

Pièces jointes

  • en cours.xlsm
    48.9 KB · Affichages: 1

BalighTomy

XLDnaute Nouveau
salut TooFatBoy, voila les 3 solutions mais rien . merci bien l’équipe 🥰
VB:
'c.UsedRange.AutoFilter 1, ">=" & CLng(CDate(TextBox1)), xlAnd, "<=" & CLng(CDate(TextBox2))
'c.UsedRange.AutoFilter 1, ">=" & 1 * CDate(Me.TextBox1.Value), xlAnd, "<=" & 1 * CDate(Me.TextBox2.Value)
'c.UsedRange.AutoFilter 1, ">=" & CLng(DateValue(Me.TextBox1.Value)), xlAnd, "<=" & CLng(DateValue(Me.TextBox2.Value))
 

Membres actuellement en ligne

Aucun membre en ligne actuellement.

Statistiques des forums

Discussions
314 628
Messages
2 111 337
Membres
111 104
dernier inscrit
JEMADA