Titre du sujet : Re: Critère de recherche ancienneté par fred777 le 15/02/2013 13:03:17
Didier,
Voici le bout de code :
Private Sub CmdVoir_Click()
'statut
If CboStatut.ListIndex <> -1 Then
statut = CboStatut.Value
Criteres = Criteres & "(bdd!U2 = """ & statut & """) * "
End If
'contrat
If CboNatcontrat.ListIndex <> -1 Then
contrat = CboNatcontrat.Value
Criteres = Criteres & "(bdd!V2 = """ & contrat & """) * "
End If
'Affectation
If CboAffectation.ListIndex <> -1 Then
Affectation = CboAffectation.Value
Criteres = Criteres & "(bdd!AE2 = """ & Affectation & """) * "
End If
'Affectation2
If CboPortage.ListIndex <> -1 Then
Portage = CboPortage.Value
Criteres = Criteres & "(bdd!AF2 = """ & Portage & """) * "
End If
'Horaire contrat
If CboHorairecont.ListIndex <> -1 Then
Horairecont = CboHorairecont.Value
Criteres = Criteres & "(bdd!Y2 = """ & Horairecont & """) * "
End If
'n° secu
If ComboBox1.ListIndex <> -1 Then
secu = ComboBox1.Value
Criteres = Criteres & "(bdd!L2 = """ & secu & """) * "
End If
'Nom JF
If ComboBox2.ListIndex <> -1 Then
Jeunefille = ComboBox2.Value
Criteres = Criteres & "(bdd!C2 = """ & Jeunefille & """) * "
End If
'Ancienneté
If ComboBox3.ListIndex <> -1 Then
ancienneté = ComboBox3.Value
Criteres = Criteres & "(bdd!AM2 > """ & "20 ans" & """) * "
End If
'Nationalité
If ComboBox4.ListIndex <> -1 Then
nationalité = ComboBox4.Value
Criteres = Criteres & "(bdd!I2 = """ & nationalité & """) * "
End If
If Optiontous.Value = True Then
tous = Optiontous.Value
Criteres = Criteres & "(bdd!A2 <> """ & "" & """) * "
Else
If Optionpresents.Value = True Then
presents = Optionpresents.Value
Criteres = Criteres & "(bdd!T2 = """ & "" & """) * "
End If
End If
If OptionButton1.Value = True Then
Féminin = OptionButton1.Value
Criteres = Criteres & "(bdd!D2 = """ & "Féminin" & """) * "
Else
If OptionButton2.Value = True Then
Masculin = OptionButton2.Value
Criteres = Criteres & "(bdd!D2 = """ & "Masculin" & """) * "
End If
End If
'à ce stade le critère se termine par *... On ajoute donc un 1. Un critère renvoie normalement
'vrai ou faux. En le multipliant par 1 il renvoie 1 ou 0 ce qui est inter^rété de la même façon par excel.
Criteres = "=" & Criteres & "1"
Sheets("filtre").Range("A2").Value = Criteres
'on utilise ensuite les critères de choix dans un filtre élaboré sur une feuille masquée
Sheets("filtre").Activate
Range("zonebdd").AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("A1:A2"), CopyToRange:=Range("A4:AN4"), Unique:=False
'Si aucune fiche ne correspond aux critères
If Range("filtre!A5").Value = "" Then
MsgBox ("Aucun nom ne répond à tous vos critères")
'S'il y a plus d'une fiche répondant au critère autrement dit si B6 non vide
'on réaffiche les fiches dans une zone de liste pour en faire choisir une à l'utilisateur
'pour cela on nomme "Fiches Filtrées" la plage contenant les titres sélectionnés.
'Il y a plusieurs façons de faire pour indiquer les coordonnées de cette plage. Ici j'ai choisi
'la fonction décaler (offset en VBA)
ElseIf Range("filtre!A5").Value <> "" Then
ActiveWorkbook.Names.Add Name:="Fiche", RefersToR1C1:= _
"=OFFSET(filtre!R5C2,,,COUNTA(filtre!C2)-1)"
Unload UsfSelection
UsfSelect2.Show
'sinon on récupère son numéro de ligne et on affiche la fiche dans le userform UsfAffiche
Else
nom = Range("A5").Value
With Sheets("bdd").Range("A:A")
Set c = .Find(Titre, LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then Lig = c.Row
End With
UserForm2.Show
End If
End Sub
Le combobox "ancienneté" est alimenté comme cela : ComboBox3.AddItem "+ de 20 ans"
Mais là, je bloque.
L'ancienneté figure dans la feuille bdd colonne AM (sous forme aa, mm, jj)
|