Count the number of rows in a worksheet with VBA - Printable Version +- QP School (https://qomplainerzschool.lima-city.de) +-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3) +--- Forum: Excel VBA Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=48) +--- Thread: Count the number of rows in a worksheet with VBA (/showthread.php?tid=5239) |
Count the number of rows in a worksheet with VBA - Qomplainerz - 07-27-2023 Example: Sub CountRows() Dim rowCount As Long rowCount = ActiveSheet.UsedRange.Rows.Count MsgBox "The number of rows in the worksheet is: " & rowCount & "." End Sub Explanation: This code defines a subroutine named CountRows. It declares a variable rowCount to hold the count of rows. The UsedRange property is used to get the range of cells that have data in the active worksheet. The Rows.Count property gets the number of rows in that range. The count of rows is then displayed in a message box. The ActiveSheet object represents the currently active worksheet. The UsedRange property returns a Range object that represents the used range on the worksheet. The Rows.Count property returns the number of rows in that range. |