Returning the Last Used Cell in a Column or Row with Worksheet : Column « Excel « VBA / Excel / Access / Word






Returning the Last Used Cell in a Column or Row with Worksheet

 
Function GetLastUsedRow(rg As Range) As Long 
    Dim lMaxRows As Long 

    lMaxRows = ThisWorkbook.Worksheets(1).Rows.Count 

    If IsEmpty(rg.Parent.Cells(lMaxRows, rg.Column)) Then 
        GetLastUsedRow = _ 
            rg.Parent.Cells(lMaxRows, rg.Column).End(xlUp).Row 
    Else 
        GetLastUsedRow = rg.Parent.Cells(lMaxRows, rg.Column).Row 
    End If 
End Function 

 








Related examples in the same category

1.Select active column
2.Select entire column
3.Select first column to last column
4.The BubbleSort() procedure sorts a column of integer values from lowest to highest value
5.converts the Integer to a String representation of the same column.
6.Array to Columns
7.Assign the value to the ColumnWidth property of the ActiveCell using:
8.Assign the column width of one cell to another cell on the active sheet, using:
9.Adjusting Column Widths
10.The Clear method
11.ClearContents method deletes the contents of the range but leaves the formatting intact.
12.ClearFormats method deletes the formatting in the range but not the cell contents.
13.The NumberFormat property represents the number format (expressed as a text string) of the Range object: statement changes the number format of column A to percent with two decimal places
14.Is in last column
15.Change column width
16.Make a range autofit