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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| Type LastCellFinder_
Left As Long
Top As Long
Right As Long
bottom As Long
End Type
Function findLastCell(ByVal rng As Range) As LastCellFinder_
Dim x As LastCellFinder_
Dim r As String
Dim c As String
Dim iMin As Long
Dim iMax As Long
' lignes
r = Replace(rng.EntireRow.Address(True, False, xlR1C1), ":", ",")
r = Replace(r, "R", "")
tmp = Split(r, ",")
iMin = 65536
For i = LBound(tmp) To UBound(tmp)
If tmp(i) < iMin Then iMin = tmp(i)
If tmp(i) > iMax Then iMax = tmp(i)
Next i
x.Top = iMin
x.bottom = iMax
' colonnes
r = Replace(rng.EntireColumn.Address(False, True, xlR1C1), ":", ",")
r = Replace(r, "C", "")
tmp = Split(r, ",")
iMin = 65536
iMax = 0
For i = LBound(tmp) To UBound(tmp)
If tmp(i) < iMin Then iMin = tmp(i)
If tmp(i) > iMax Then iMax = tmp(i)
Next i
x.Left = iMin
x.Right = iMax
findLastCell = x
End Function |
Partager