Usf qui permet recherche selon interval date

marabane

XLDnaute Nouveau
Slt les excelnautes !!

Voilà, sur le fichier joint j'aimerais créer un usf qui va me permettre de faire des recherches selon une intervalle de date et de m'afficher le résultat sur une nouvelle feuille.

Je suis bloqué à ce niveau et j'espere un coup de main de votre part.

Merci d'avance.
 

Pièces jointes

  • recherche.zip
    3.1 KB · Affichages: 79
  • recherche.zip
    3.1 KB · Affichages: 75
  • recherche.zip
    3.1 KB · Affichages: 76

jp14

XLDnaute Barbatruc
Re : Usf qui permet recherche selon interval date

Bonjour

Pour répondre à cette demande il faudrait un peu plus d'explications.

"recherches selon une intervalle de date"
Dans la base de données on trouve 4 colonnes avec des dates !


"résultat sur une nouvelle feuille"
Quel est le résultat à obtenir ?



JP
 

jp14

XLDnaute Barbatruc
Re : Usf qui permet recherche selon interval date

Bonjour

Ci joint un fichier avec un usf et une macro qui copie des lignes en fonction des dates choisies.

A tester et à modifier

JP
 

Pièces jointes

  • recherche.zip
    16.4 KB · Affichages: 95
  • recherche.zip
    16.4 KB · Affichages: 99
  • recherche.zip
    16.4 KB · Affichages: 106

marabane

XLDnaute Nouveau
Re : Usf qui permet recherche selon interval date

Bonjour le forum,

JP14 si tu es là peux tu m'aider avec le code que tu m'a envoyé STP ? Tu me le commente pour que ce soit clair pour moi j'essaye de l'adapter à mon probléme mais j'ai des difficultés.

Cela ne semble pas interreser les autres alors si tu peux m'aider, Merci.

Voici comment je l'ai adapté :
Code:
Option Explicit
'
Dim nomfeuille1 As String
Dim col1 As String
Dim lidep1 As Long

Dim lidep2 As Long
Dim nomfeuille2 As String
Dim col2 As String

Dim data1 As String

Dim chemin As String
Dim classeur1 As String

Dim date1 As Date
Dim date2 As Date

Dim nb As Integer
Dim trouve As Boolean
Dim sh As Worksheet
Dim j As Long


Private Sub CommandButton1_Click()
Unload Me
End Sub

'-------------------------------------------------------------------------------------
' Module    : UserForm1/CommandButton2_Click
' DateTime  : 20/11/2008 / 19:29
' Auteur    : JP14
' Bouton          :valider
'-------------------------------------------------------------------------------------
Private Sub CommandButton2_Click()
Dim i As Long
Dim j As Long
Dim dl1 As Long
Dim dl2 As Long

Dim cellule As Range
Dim plage As Range

Dim lidep2 As Long
Dim nomfeuille2 As String
Dim col2 As String

Dim date1 As Date
Dim date2 As Date

'**********************************
dl1 = Sheets("Données").Range("a65536").End(xlUp).Row + 2

nomfeuille2 = "resultat" '"Données"
col2 = "a"
lidep2 = 2
dl2 = Sheets("resultat").Range("a65536").End(xlUp).Row + 1
'************************************
If IsDate(ComboBox1.Value) Then
    date1 = ComboBox1.Value
Else
    Call MsgBox("Date de début non conforme" _
                & vbCrLf & "" _
                , vbCritical, Application.Name)
    Exit Sub
End If
If IsDate(ComboBox2.Value) Then
    date2 = ComboBox2.Value
Else
    Call MsgBox("Date de fin non conforme" _
                & vbCrLf & "" _
                , vbCritical, Application.Name)
    Exit Sub
End If

With Sheets("Données")
Set plage = .Range(col1 & lidep1 & ":" & col1 & .Range(col1 & "65536").End(xlUp).Row)
For Each cellule In plage
     If IsDate(cellule.Value) Then
        If date1 <= cellule.Value And cellule.Value <= date2 Then
        ' dans la plage on copie
        Call ajoutlig(nomfeuille2, "a", nomfeuille1, cellule.Row)
        End If
     End If
Next cellule

End With

End Sub


Private Sub OptionButton1_Click()
If OptionButton1.Value = True Then
ComboBox1.Clear
ComboBox2.Clear
ComboBox1.Style = fmStyleDropDownCombo
ComboBox2.Style = fmStyleDropDownCombo
    'Récupère les données de la colonne g...
With Sheets("Données")

    For j = lidep1 To .Range("AB65536").End(xlUp).Row
    
        If ComboBox1.ListCount > 0 Then ComboBox1.Value = Sheets("Données").Range("AB" & j)
        
        '...et filtre les doublons
        If ComboBox1.ListIndex = -1 Then
            ComboBox1.AddItem .Range("AB" & j)
            ComboBox2.AddItem .Range("AB" & j)
        End If
    Next j


End With
End If
ComboBox1.Value = ""
ComboBox1.Style = fmStyleDropDownList
ComboBox2.Style = fmStyleDropDownList
col1 = "AB"
End Sub

Private Sub OptionButton2_Click()
If OptionButton2.Value = True Then
ComboBox1.Style = fmStyleDropDownCombo
ComboBox2.Style = fmStyleDropDownCombo
    'Récupère les données de la colonne g...
With Sheets("données")
ComboBox1.Clear
ComboBox2.Clear
    For j = lidep1 To Range("Ad65536").End(xlUp).Row
        If ComboBox1.ListCount > 0 Then ComboBox1.Value = .Range("AB" & j)
        'ComboBox1.Value = .Range("Ad" & j)
        '...et filtre les doublons
        If ComboBox1.ListIndex = -1 Then
        ComboBox1.AddItem .Range("Ad" & j)
        ComboBox2.AddItem .Range("Ad" & j)
        End If
    Next j


End With
End If
col1 = "AD"
ComboBox1.Value = ""
ComboBox1.Style = fmStyleDropDownList
ComboBox2.Style = fmStyleDropDownList
End Sub

Private Sub UserForm_Initialize()
nomfeuille1 = "Feuil1"
lidep1 = 2

End Sub
Private Sub ajoutlig(£nomdest As String, £col As String, £nomorigine As String, £ligacop As Long)
 Call ajoutlig
 '("feuille destination", "colonne pour trouver la dernière ligne", "feuille origine", "ligne à copier")
With Sheets("resultat")

  
    Sheets(£nomorigine).Rows(£ligacop).Copy _
     Destination:=.Rows(.Range(£col & "65536").End(xlUp).Row + 1)
 End With
End Sub
 

marabane

XLDnaute Nouveau
Re : Usf qui permet recherche selon interval date

A PARTIR DE LA JE PIGE COMPLETEMENT QUE DAL
End Sub
Private Sub ajoutlig(£nomdest As String, £col As String, £nomorigine As String, £ligacop As Long)
Call ajoutlig ("feuille destination", "colonne pour trouver la dernière ligne", "feuille origine", "ligne à copier")
With Sheets("resultat")


Sheets(£nomorigine).Rows(£ligacop).Copy _
Destination:=.Rows(.Range(£col & "65536").End(xlUp).Row + 1)
End With
End Sub
[/CODE][/QUOTE]
 

jp14

XLDnaute Barbatruc
Re : Usf qui permet recherche selon interval date

Bonsoir


Ci joint l'userform avec des commentaires au niveau des procédures.
Il suffit pour le visualiser de faire la manipulation suivante
A près décompression utiliser l'option importer un fichier de l'éditeur VBA et sélectionner Userform1.

JP
 

Pièces jointes

  • UserForm1.zip
    2.8 KB · Affichages: 95
  • UserForm1.zip
    2.8 KB · Affichages: 76
  • UserForm1.zip
    2.8 KB · Affichages: 77

Discussions similaires

Statistiques des forums

Discussions
312 836
Messages
2 092 648
Membres
105 477
dernier inscrit
kyra