Simple way to count the used rows in a column

Glory

Well-known Member
Joined
Mar 16, 2011
Messages
640
These all fail

Code:
MsgBox ActiveSheet.Columns("A").UsedRange.Count
MsgBox ActiveSheet.Columns("A").Cells.UsedRange.Count
MsgBox ActiveSheet.Columns("A").Rows.UsedRange.Count
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Maybe?

msgbox worksheetfunction.counta(activesheet.columns("A"))

but this will only count cells that have data in them and not include cells that are blank.
 
Upvote 0
Code:
    MsgBox Application.WorksheetFunction.CountA _
        (Range("A1", Range("A" & Rows.Count).End(xlUp)))
 
Upvote 0
Thanks guys.

VoG: VBA's help says this about the "Row" property:

"Returns the number of the first row of the first area in the range."

Emphasis added. Why specify the "first area"? Why not just say "first row in the range"?
 
Upvote 0
Thanks guys.

VoG: VBA's help says this about the "Row" property:

"Returns the number of the first row of the first area in the range."

Emphasis added. Why specify the "first area"? Why not just say "first row in the range"?

consider the code:
Code:
Sub test()
    Set rng = Range("A10:C20,F5:G10")
    Debug.Print rng.Row
End Sub
You could argue that the answer should be 5 as this is the first row in the range. However, since the range consists of 2 "areas", the code returns 10, which is the first row of the first area.
 
Upvote 0
Code:
MsgBox ActiveSheet.UsedRange.Rows.Count

Or perhaps you are looking for :-

Code:
MsgBox Range([A1], ActiveSheet.UsedRange).Rows.Count
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,672
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top