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
| MsgBox findLastRow2(1, 1, 1, "") 'OK
MsgBox findLastColumn2(1, 1, 10, "") ' KO
Function findLastRow2(counter, start_line, colonne, value_to_stop)
findLastRow2 = findLastAbstract(counter, start_line, colonne, MAXLINE, colonne, value_to_stop) 'line
End Function
Function findLastColumn2(counter, line, start_column, value_to_stop)
findLastColumn2 = findLastAbstract(counter, line, start_column, line, MAXCOLUMN, value_to_stop) 'column
End Function
Function findLastAbstract(counter, start_line, start_column, max_line, max_column, value_to_stop)
'trouve la dernière ligne entre un start et une value dans une colonne (retourne 0 si pas de ligne)
Dim plage As Range, cell As Range
Set plage = Range(Cells(start_line, start_column), Cells(max_line, max_column))
For Each cell In plage
If cell.value = value_to_stop Then
Exit For
Else: counter = counter + 1
End If
Next
If counter > 1 Then
findLastAbstract = counter - 1
Else: findLastAbstract = 0
End If
End Function |
Partager