Merci Joe !
Pour diminuer le nombre d'argument, tu peux imposer alors le Range source, plus besoin d'un argument pour la feuille …
Mes procédures Demo1 & 2 ne fonctionnent que si Feuil1 est déjà active …
Voici une fonction alimentant une variable tableau des valeurs filtrées et de leurs adresses :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| Function FilterColumnArray(Rcol As Range, CRITERIA$)
Dim Rc As Range, Rg As Range
FilterColumnArray = Split("")
If Rcol.Columns.Count > 1 Then Exit Function
Application.ScreenUpdating = False
With Rcol.Rows
.AutoFilter
.AutoFilter 1, CRITERIA
L& = Application.Subtotal(103, .Cells) - 1
If L Then
ReDim AR(1 To L, 1 To 2)
For Each Rg In .Item("2:" & .Count).SpecialCells(xlCellTypeVisible).Areas
For Each Rc In Rg
R& = R& + 1
AR(R, 1) = Rc.Value
AR(R, 2) = Rc.Address
Next
Next
FilterColumnArray = AR
End If
.AutoFilter
End With
End Function
Sub Demo3()
With Feuil1
VF = FilterColumnArray(.Cells(1).CurrentRegion.Columns(3), "Montpellier")
If UBound(VF) >= 2 Then .Activate: .Range(VF(2, 2)).Select
End With
End Sub |
Mais s'il est juste question de sélectionner la n-ième cellule d'une colonne correspondant à un critère,
pas la peine de gâcher des ressources ni de filtrer, la méthode Find s'en acquitte très bien !
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| Sub FindSelect(ByVal Rg As Range, WHAT, Optional ORDER% = 1)
Dim Rf As Range
With Rg
Set Rf = .Find(WHAT, .Cells(.Cells.Count), xlValues, xlWhole, xlByColumns, xlNext)
If Not Rf Is Nothing Then
AD$ = Rf.Address
Do
N% = N% + 1: If N = ORDER Then Exit Do
Set Rf = .FindNext(Rf)
Loop Until Rf.Address = AD
If N = ORDER Then Rf.Parent.Activate: Rf.Select
Set Rf = Nothing
End If
End With
Set Rg = Nothing
End Sub
Sub Demo4()
FindSelect Feuil1.Cells(1).CurrentRegion.Columns(3), "Montpellier", 2
End Sub |
_____________________________________________________________________________________________________
Découvrir, c’est voir la même chose que les autres et penser autrement. (Albert von Szent-Györgyi)
Partager