Mega Code Archive

 
Categories / VisualBasic Script / Forms
 

Finding the Last Used Cell in a Column or Row

Function GetLastCellInColumn(rg As Range) As Range      Dim lMaxRows As Long      lMaxRows = ThisWorkbook.Worksheets(1).Rows.Count      If IsEmpty(rg.Parent.Cells(lMaxRows, rg.Column)) Then          Set GetLastCellInColumn = _              rg.Parent.Cells(lMaxRows, rg.Column).End(xlUp)      Else          Set GetLastCellInColumn = rg.Parent.Cells(lMaxRows, rg.Column)      End If  End Function