'----------------------------------------------------------------------
'Calcul de la dernière ligne non vide d'une colonne avec fonction Match
'Colonne: numéro ou lettre
'----------------------------------------------------------------------
Function MatchDernièreLigneEnColonne(ByVal Feuille As Worksheet, ByVal Colonne As Variant) As Long
Const ChaineMax As String = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
Const NombreMax As Double = (2 ^ 53 - 1) * 2 ^ 971
Dim RngColonne As Range
Dim RngErrors As Range
Dim ErrorLine As Long
Dim xlCellType As Integer
Set RngColonne = Feuille.Columns(Colonne)
xlCellType = xlCellTypeFormulas
GoSub GetErrorLine
xlCellType = xlCellTypeConstants
GoSub GetErrorLine
With Application
MatchDernièreLigneEnColonne = .Max(.IfError(.Match(ChaineMax, RngColonne, 1), 0), _
.IfError(.Match(NombreMax, RngColonne, 1), 0), _
ErrorLine)
End With
Exit Function
GetErrorLine:
On Error Resume Next
Set RngErrors = RngColonne.SpecialCells(xlCellType, xlErrors)
If Err.Number = 0 Then
Set RngErrors = RngErrors.Areas(RngErrors.Areas.Count)
ErrorLine = Application.Max(ErrorLine, RngErrors.Cells(RngErrors.Cells.Count).Row)
End If
On Error GoTo 0
Return
End Function