la fonction se situe dans un classeur Excel de type add-in. elle est appelée par un autre classeur Excel.
Ci-dessous le code :
Public Function GetLastRow(Optional lngColNumber1 As Long = 1, _
Optional lngColNumber2 As Long = 50, _
Optional lngRowMax As Long = 65536, _
Optional wksWorksheet As Worksheet = Nothing) As Long
Dim I As Long
Dim wksCurrentWorkSheet As Worksheet
' Récupération des paramètres globaux actuel
Set wksCurrentWorkSheet = ActiveSheet
' Initialisations
GetLastRow = 0
If wksWorksheet Is Nothing Then
Set wksWorksheet = wksCurrentWorkSheet
End If
With wksWorksheet
.Select
For I = lngColNumber1 To lngColNumber2
If .Cells(lngRowMax, I).Value <> "" Then GetLastRow =
ActiveCell.Row
.Cells(lngRowMax, I).Select
Selection.End(xlUp).Select
If ActiveCell.Row > GetLastRow And _
ActiveCell.Value <> "" Then GetLastRow = ActiveCell.Row
Next
End With
wksCurrentWorkSheet.Select
End Function
La ligne qui plante est " .Select"