Find last row in a columnar data range

OaklandJim

Well-known Member
Joined
Nov 29, 2018
Messages
833
Office Version
  1. 365
Platform
  1. Windows
I know that this has probably been answered a million times but I cannot hack out the necessary code to find the last occupied row in a columnar range of data. Here are my hacky attempts so far.

VBA Code:
Function LastOccupiedRow(rData As Range) As Long
    
Debug.Print rData.Address '<= reports range G10:G109

'   FYI the last occupied row in rData = 38

'   This reports 1
    LastOccupiedRow = Cells(rData.Rows.Count, 1).End(xlUp).Row

'   These report 9

    'LastOccupiedRow = rData.Cells(1).Resize(rData.Rows.Count).End(xlUp).Row
    
    'LastOccupiedRow = rData.Cells(1, 1).Resize(rData.Rows.Count, 1).End(xlUp).Row
    
    'LastOccupiedRow = rData.End(xlUp).Row

End Function
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Maybe...
VBA Code:
Public Function LastOccupiedRow(rData As Range)
LastOccupiedRow = rData.Find(What:="*", After:=rData.Cells(1, 1), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End Function
 
Upvote 0
Solution

Forum statistics

Threads
1,214,874
Messages
6,122,036
Members
449,062
Latest member
mike575

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top