returns a number that represents the last nonempty cell in the same row : Row « Excel « VBA / Excel / Access / Word






returns a number that represents the last nonempty cell in the same row

 
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 

 








Related examples in the same category

1.change row height
2.Select active row
3.Clearing a range differs from deleting a range. When you delete a range, Excel shifts the remaining cells around to fill up the range you deleted.
4.Select entire row
5.Select first to last row
6.Get the last row and last cell
7.Set the color row by row
8.Delete empty rows
9.Bold cells in a Row
10.Array to rows
11.Array to rows - method (Limited to 65,536)
12.Is in last row