How To Select Last Row In Excel Vba


<div>
   <pre>
   <code>
   Sub SelectLastRow()
      Dim LastRow As Long
      LastRow = Cells(Rows.Count, 1).End(xlUp).Row
      Rows(LastRow).Select
   End Sub
   </code>
   </pre>
   <p>
   The above VBA code demonstrates how to select the last row in an Excel worksheet using VBA.
   </p>
   <p>
   Here's how it works:
   </p>
   <p>
   1. The first line defines a subroutine called "SelectLastRow".
   </p>
   <p>
   2. The second line declares a variable called "LastRow" as a Long data type.
   </p>
   <p>
   3. The third line uses the "Cells" method to determine the last row in the first column (column A). "Rows.Count" returns the total number of rows in the worksheet, and "xlUp" is used to find the last used cell in the specified range.
   </p>
   <p>
   4. The fourth line selects the entire row of the last row in the worksheet.
   </p>
   <p>
   After running this code, the last row in the worksheet will be selected.
   </p>
   </div>

Same cateogry post

Leave a comment