XL 2010 DEPLACER CELLULE POUR FILTRER

mcj1997

XLDnaute Accro
Bonjour,

Problème pour réaliser un filtre avec numéro de semaine sans avoir à afficher le numéro de semaine, fichier en PJ.

Merci d'avance,
 

Pièces jointes

  • DEPLACER CELLULE FILTRE.xlsx
    9.9 KB · Affichages: 9

JHA

XLDnaute Barbatruc
Bonjour à tous,

En masquant la colonne et avec un segment dans une autre feuille ou sur même feuille.
Liste déroulante sans doublon et tableau recap de la semaine.


JHA
 

Pièces jointes

  • DEPLACER CELLULE FILTRE.xlsx
    18.2 KB · Affichages: 4

job75

XLDnaute Barbatruc
Bonjour mcj1997, JHA,

Voyez le fichier joint et ces 2 macros dans le code de la feuille :
VB:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim tablo, d As Object, i&
With [A3].CurrentRegion
    .Sort .Cells(1), xlAscending, Header:=xlYes 'tri sur les dates
    tablo = .Resize(, 2) 'matrice, plus rapide, au moins 2 éléments
End With
Set d = CreateObject("Scripting.Dictionary")
For i = 2 To UBound(tablo)
    If IsDate(tablo(i, 1)) Then d(Application.WeekNum(tablo(i, 1), 2)) = ""
Next
With [G1].Validation
    .Delete
    If d.Count = 0 Then Exit Sub
    .Add xlValidateList, Formula1:=Join(d.keys, ",")
End With
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, [G1]) Is Nothing Then Exit Sub
Dim sem As Byte, i&
sem = [G1] 'critère
Application.ScreenUpdating = False
If FilterMode Then ShowAllData 'si la feuille est filtrée
With [A3].CurrentRegion
    .Rows.Hidden = False
    For i = 2 To .Rows.Count
        If sem And IsDate(.Cells(i, 1)) Then If (Application.WeekNum(.Cells(i, 1), 2)) <> sem Then .Rows(i).Hidden = True
    Next
End With
End Sub
La 1ère macro crée la liste de validation en G1, la 2ème filtre le tableau.

J'ai supprimé la colonne A avec les numéros de semaines, elle était inutile.

A+
 

Pièces jointes

  • FILTRE(1).xlsm
    19.4 KB · Affichages: 3
Dernière édition:

job75

XLDnaute Barbatruc
Si l'on ne veut pas modifier l'ordre des dates du tableau utiliser la macro de tri Quick sort :
VB:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim tablo, d As Object, i&, a
tablo = [A3].CurrentRegion.Resize(, 2) 'matrice, plus rapide, au moins 2 éléments
Set d = CreateObject("Scripting.Dictionary")
For i = 2 To UBound(tablo)
    If IsDate(tablo(i, 1)) Then d(Application.WeekNum(tablo(i, 1), 2)) = ""
Next
With [G1].Validation
    .Delete
    If d.Count = 0 Then Exit Sub
    a = d.keys
    tri a, 0, UBound(a)
    .Add xlValidateList, Formula1:=Join(a, ",")
End With
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, [G1]) Is Nothing Then Exit Sub
Dim sem As Byte, i&
sem = [G1] 'critère
Application.ScreenUpdating = False
If FilterMode Then ShowAllData 'si la feuille est filtrée
With [A3].CurrentRegion
    .Rows.Hidden = False
    For i = 2 To .Rows.Count
        If sem And IsDate(.Cells(i, 1)) Then If (Application.WeekNum(.Cells(i, 1), 2)) <> sem Then .Rows(i).Hidden = True
    Next
End With
End Sub

Sub tri(a, gauc, droi) ' Quick sort
Dim ref, g, d, temp
ref = a((gauc + droi) \ 2)
g = gauc: d = droi
Do
    Do While a(g) < ref: g = g + 1: Loop
    Do While ref < a(d): d = d - 1: Loop
    If g <= d Then
      temp = a(g): a(g) = a(d): a(d) = temp
      g = g + 1: d = d - 1
    End If
Loop While g <= d
If g < droi Then Call tri(a, g, droi)
If gauc < d Then Call tri(a, gauc, d)
End Sub
Fichier (2).
 

Pièces jointes

  • FILTRE(2).xlsm
    20.5 KB · Affichages: 9

job75

XLDnaute Barbatruc
Bonjour mcj1997, JHA, le forum,

Pour le filtrage il vaut mieux utiliser le filtre avancé, voyez ce fichier (3) :
VB:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, [G1]) Is Nothing Then Exit Sub
[F4] = "=OR(WEEKNUM(A4,2)=G$1,G$1=0)" 'critère
[A3].CurrentRegion.AdvancedFilter xlFilterInPlace, [F3:F4]
[F4] = ""
End Sub
C'est bien plus rapide s'il y a beaucoup de dates, j'ai testé en copiant la plage A4:A12 sur 18 000 lignes : le filtrage est immédiat alors qu'il prend 3 secondes sur le fichier (2).

A+
 

Pièces jointes

  • FILTRE(3).xlsm
    20.3 KB · Affichages: 6

Discussions similaires

Statistiques des forums

Discussions
312 029
Messages
2 084 775
Membres
102 662
dernier inscrit
seb60240