Function GetLastCellInRow(rg As Range) As Range
Dim lMaxColumns As Long
lMaxColumns = ThisWorkbook.Worksheets(1).Columns.Count
If IsEmpty(rg.Parent.Cells(rg.Row, lMaxColumns)) Then
Set GetLastCellInRow = _
rg.Parent.Cells(rg.Row, lMaxColumns).End(xlToLeft)
Else
Set GetLastCellInRow = rg.Parent.Cells(rg.Row, lMaxColumns)
End If
End Function
|