'************************************************************************************
' FONCTION FIND(LAST) ROW,COLUMN,CELL ON <<<defined range>>>
'Autor:patricktoulon
'version beta
'date version 29/03/2020
'************************************************************************************
Function UsedrangeOnRangeDef(tableau) As Range
Dim lig&, col&, cel1 As Range, cel2 As Range, truc$
With tableau
With .Parent.AutoFilter
If .Range.Address = tableau.Address Then
'ici on recupere le critere du filtre
For i = 1 To .Filters.Count
If .Filters.Item(i).On Then truc = .Filters.Item(i).Criteria1
Next
MsgBox truc 'juste pour voir
If Not .Parent.AutoFilter Is Nothing Then .Parent.AutoFilter.ShowAllData 'ici on enleve le filtre
End If
End With
Set cel1 = .Cells(1)
col = .Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
lig = .Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Set cel2 = Cells(lig, col)
Set UsedrangeOnRangeDef = .Parent.Range(cel1, cel2)
.AutoFilter Field:=1, Criteria1:=truc 'ICI ON REMET LE FILTRE COMME IL ETAIT
End With
End Function
'sub de test
Sub testusedRangedef()
Dim plage As Range
Set plage = [A1:A6000]
MsgBox UsedrangeOnRangeDef(plage).Address
End Sub