Counting number of rows in table

mst3k4L

Board Regular
Joined
Nov 3, 2011
Messages
55
I'm not sure why this is being so difficult, but for some reason I can't seem to count the number of rows in a given table. I keep getting an error which states:

Run-time error '424':
Object required

Any help is appreciated. Code is below, and I'm using Excel 2007. Thanks in advance.

Code:
Sub QC()
    Dim TableRows As Integer
    
    TableRows = Activeworksheet.Tables("CAPEX").Rows.Count
    
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Excel "tables" are ListObjects...(also: there is no "activeworksheet"...use this: ActiveSheet)

Try this:
Code:
Sub QC()
    Dim TableRows As Integer
    
    TableRows = ActiveSheet.ListObjects("CAPEX").Range.Rows.Count
End Sub


Edited to include this alternative structure:
Code:
Sub QC1()
    Dim TableRows As Integer
    TableRows = [CAPEX[#All]].Rows.Count
    MsgBox TableRows
End Sub
Is that something you can work with?
 
Last edited:
Upvote 0
Excel "tables" are ListObjects...(also: there is no "activeworksheet"...use this: ActiveSheet)

Try this:
Code:
Sub QC()
    Dim TableRows As Integer
    
    TableRows = ActiveSheet.ListObjects("CAPEX").Range.Rows.Count
End Sub

That did it! Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,539
Messages
6,120,100
Members
448,944
Latest member
SarahSomethingExcel100

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