Why am I getting an Application-Defined or an Object-Defined?

Shafty

New Member
Joined
Mar 20, 2017
Messages
43
Code:
Public Sub IT_Estimation()Dim Employees As ListObject
    Set Employees = ThisWorkbook.Sheets("Employees").ListObjects("Employees")
Dim Individuals As Workbook
    Set Individuals = ThisWorkbook.Parent.Workbooks.Add
    With Individuals
        .Sheets.Add After:=Individuals.Sheets.Count, Count:=Employees.ListRows.Count
    End With
End Sub

I am getting error on the below code
Code:
.Sheets.Add After:=Individuals.Sheets.Count, Count:=Employees.ListRows.Count

Please Help. Thank You
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
As I understand it (perhaps incorrectly), ListRows is a property of ListObject (no "s"), whereas Employees is the collection ListObjects (with "s"). ListRows is not a property of the collection ListObjects.

Perhaps Count:=Employees(1).ListRows.Count will work syntactically.

But I do now know if that is the right answer semantically, if Employees might have more than one object.

I wonder if you should write Count:=nrows, where nrows is determined by one of the following (you decide which is more appropriate):

Code:
Dim nrows As Long, obj As Variant

For Each obj in Employees
    nrows = nrows + obj.ListRows.Count  ' sum of ListRows.Count
Next

or

For Each obj in Employees
    If obj.ListRows.Count > nrows Then nrows = obj.ListRows.Count  ' max ListRows.Count
Next
 
Upvote 0
As I understand it (perhaps incorrectly), ListRows is a property of ListObject (no "s"), whereas Employees is the collection ListObjects (with "s"). ListRows is not a property of the collection ListObjects. Perhaps Count:=Employees(1).ListRows.Count will work syntactically.

A total misdirection. Sorry.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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