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