XLA routines: EE_GetLastPopulatedCell

Finds the last populated cell on a worksheet, or an empty cell representing the max row and max col.
Function EE_GetLastPopulatedCell(Optional wks As Worksheet) As Range '- Works how specialcells (lastCell) SHOULD work '- Returns single cell range Dim lngCol As Long Dim lngMaxRow As Long Dim lngRow As Long Dim lngMaxCol As Long 'http://excelexperts.com/xla-routines-eeGetLastPopulatedCell for updates on this function If wks Is Nothing Then Set wks = ActiveSheet End If If wks.UsedRange.Rows.Count = 1 And wks.UsedRange.Columns.Count = 1 Then Set EE_GetLastPopulatedCell = wks.UsedRange.Cells(1, 1) Exit Function End If lngMaxRow = wks.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row lngMaxCol = wks.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column Set EE_GetLastPopulatedCell = wks.Cells(lngMaxRow, lngMaxCol) End Function
»
- Nick's blog
- Login or register to post comments
- 4171 reads
Recent comments
6 years 3 weeks ago
6 years 41 weeks ago
7 years 1 week ago
7 years 3 weeks ago
7 years 5 weeks ago
7 years 10 weeks ago
7 years 18 weeks ago
7 years 19 weeks ago
7 years 19 weeks ago
7 years 19 weeks ago