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
- 3983 reads
Recent comments
5 years 36 weeks ago
6 years 22 weeks ago
6 years 34 weeks ago
6 years 37 weeks ago
6 years 38 weeks ago
6 years 43 weeks ago
6 years 52 weeks ago
7 years 2 days ago
7 years 3 days ago
7 years 3 days ago