vba:excel:functions:getlastrowcol
[VBA] [Excel] Letzte gefüllte Zeile/Spalte
'/**
' * ermitteln der letzten gefüllten Zeile eines Worksheets
' * Die Funktion Sheet.Cells.SpecialCells(xlCellTypeLastCell) liefert auch instanzierte Zeilen ohne Inhalt
' * http://wiki.yaslaw.info/wikka/vbaExcelGetLastRowCol
' * @param Worksheet Eine Referenz auf das Worksheet
' * @return Long Zeilenindex der letzten Zeile mit Inhalt
' */
Public Function xlsGetLastRow(ByRef Sheet As Excel.Worksheet) As Long
Dim r As Variant
xlsGetLastRow = Sheet.Cells.SpecialCells(xlCellTypeLastCell).row
For r = xlsGetLastRow To 1 Step -1
If Sheet.Application.WorksheetFunction.CountA(Sheet.rows(r)) = 0 Then
xlsGetLastRow = r - 1
Else
Exit For
End If
Next r
End Function
'/**
' * ermitteln der letzten gefüllten Spalte eines Worksheets
' * Die Funktion Sheet.Cells.SpecialCells(xlCellTypeLastCell) liefert auch instanzierte Spalten ohne Inhalt
' * http://wiki.yaslaw.info/wikka/vbaExcelGetLastRowCol
' * @param Worksheet Eine Referenz auf das Worksheet
' * @return Long Spaltenindex der letzten Zeile mit Inhalt
' */
Public Function xlsGetLastCol(ByRef Sheet As Excel.Worksheet) As Long
Dim i As Variant
xlsGetLastCol = Sheet.Cells.SpecialCells(xlCellTypeLastCell).Column
For i = xlsGetLastCol To 1 Step -1
If Sheet.Application.WorksheetFunction.CountA(Sheet.Columns(i)) = 0 Then
xlsGetLastCol = i - 1
Else
Exit For
End If
Next i
End Function
vba/excel/functions/getlastrowcol.txt · Last modified: 09.12.2013 09:39:54 (external edit)