'************************************************************************************
' FONCTION FIND(LAST) ROW,COLUMN,CELL ON <<<defined range>>>
'Author:patricktoulon
'version beta test
'date version 29/03/2020
'************************************************************************************
Function UsedrangeOnRangeDef(tableau) As Range
Dim lig&, col&, cel1 As Range, cel2 As Range
With tableau
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)
End With
End Function
'sub de test
Sub testusedRangedef()
Dim plage As Range
Set plage = [E4:I16]
MsgBox UsedrangeOnRangeDef(plage).Address
End Sub
'
'
'cherche la derniere colonne utilisée dans une plage
Function LastColumnUsedOnRangeDef(plage, Optional ByVal intra As Boolean = False)
With plage'.Resize(plage.Rows.Count)
LastColumnUsedOnRangeDef = .Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column - IIf(intra, plage.Column - 1, 0)
End With
End Function
'sub de test
Sub testLastCol()
Dim plage As Range
Set plage = [E4:I16]
MsgBox LastColumnUsedOnRangeDef(plage, True)
End Sub
'
'
'cherche la derniere ligne utilisée dans une plage
Function LastRowUsedOnRangeDef(ByRef plage, Optional ByVal intra As Boolean = False)
LastRowUsedOnRangeDef = plage.Resize(plage.Rows.Count + 1).Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row - IIf(intra, plage.Row - 1, 0)
End Function
'sub de test
Sub testLastRow()
Dim plage As Range
Set plage = [E4:I16]
MsgBox LastRowUsedOnRangeDef(plage, True)
End Sub
'
'
'cherche la derniere cellule utilisée dans une plage
Function LastCellUsedOnRangeDef(plage)
With plage
Set LastCellUsedOnRangeDef = .Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
End With
End Function
'sub de test
Sub testLastcell()
Dim plage As Range
Set plage = [E4:I16]
MsgBox LastCellUsedOnRangeDef(plage).Address
End Sub