Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Count the number of rows in a worksheet with VBA
#1
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.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy data to another worksheet Qomplainerz 0 399 07-27-2023, 11:24 AM
Last Post: Qomplainerz
  Count colored cells with VBA Qomplainerz 0 357 07-27-2023, 11:07 AM
Last Post: Qomplainerz
  Calculate factorial of a given number in VBA Qomplainerz 0 389 07-27-2023, 11:04 AM
Last Post: Qomplainerz
  Create a pivot table based on data in a worksheet with VBA Qomplainerz 0 415 07-27-2023, 09:48 AM
Last Post: Qomplainerz
  Delete rows based on a condition Qomplainerz 0 406 07-27-2023, 09:47 AM
Last Post: Qomplainerz
  Filter data in a worksheet Qomplainerz 0 382 07-27-2023, 09:46 AM
Last Post: Qomplainerz
  Protect and unprotect worksheet with VBA Qomplainerz 0 303 07-27-2023, 08:20 AM
Last Post: Qomplainerz
  Create a new worksheet and rename it with VBA Qomplainerz 0 308 07-27-2023, 08:14 AM
Last Post: Qomplainerz
  Calculate the factorial of a number with VBA Qomplainerz 0 360 07-27-2023, 07:56 AM
Last Post: Qomplainerz
  Worksheet methods in VBA Qomplainerz 0 281 07-26-2023, 08:44 PM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 5 Guest(s)