letzte Zelle daher auch Spalte mit Function
22.11.2009 07:03:02
Tino
Hallo,
hier eine Möglichkeit die letzte Zelle im benutzten Bereich zu finden,
damit hast Du auch die letzte Spalte.
Ist eigentlich die die letzte Zelle im Usedrange, aber wie bekannt ist, ist diese oft unzuverlässig,
wenn Zellen nicht richtig gelöscht wurden.
Function FindLetzte(mySH As Worksheet) As Range
Dim LRow As Long, LCol As Long
Dim A As Long
With mySH.UsedRange
On Error Resume Next
'Finde Zeile
LRow = .Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False, False).Row
LRow = Application.Max(LRow, .Find("*", , xlFormulas, xlWhole, xlByRows, xlPrevious).Row)
If LRow = 0 Then LRow = 1
'Finde Spalte
For A = .Columns(.Columns.Count).Column To .Columns(1).Column Step -1
LCol = mySH.Columns(A).Find("*", , xlValues, xlWhole, xlByRows, xlPrevious).Column
LCol = Application.Max(LCol, mySH.Columns(A).Find("*", , xlFormulas, xlWhole, xlByRows, xlPrevious).Column)
If LCol > 1 Then: LCol = A: Exit For
Next A
If LCol = 0 Then LCol = 1
End With
Set FindLetzte = mySH.Cells(LRow, LCol)
End Function
Sub Beispiel()
MsgBox FindLetzte(ActiveSheet).Address
End Sub
Gruß Tino