Count Property

Returns the number of items in the specified collection or object.

For the objects Day, Month, Period, Year; and for the collections Days, Months, and Years, Count is Read-only Integer.

For all other objects and collections, Count is Read-only Long.

Remarks

Returns 1 when applied to the Day object. For the Month, Year, or Period objects, returns the number of days in the month, year, or period.

Example

The following example prompts the user for the name of a resource and then assigns that resource to tasks without any resources.

Sub AssignResource()

    Dim T As Task            ' Task object used in For Each loop
    Dim R    As Resource        ' Resource object used in For Each loop
    Dim Rname As String    ' Resource name
    Dim RID As Long        ' Resource ID

    RID = 0
    RName = InputBox$("Enter the name of a resource: ")

    For Each R in ActiveProject.Resources
        If R.Name = RName Then
            RID = R.ID
            Exit For
        End If
    Next R

    If RID <> 0 Then
        ' Assign the resource to tasks without any resources.
        For Each T In ActiveProject.Tasks
            If T.Assignments.Count = 0 Then
                T.Assignments.Add ResourceID:=RID
            End If
        Next T
    Else
        MsgBox Prompt:=RName & " is not a resource in this project.", buttons:=vbExclamation
    End If

End Sub

Applies to | Assignment Object, Assignments Collection Object | Availability Object, Availabilities Collection Object | Calendar Object, Calendars Collection Object | CodeMask Collection Object | CostRateTable Object, CostRateTables Collection Object | Day Object, Days Collection Object | Day Object, Days Collection Object | Filter Object, Filters Collection Object | Group Object, Groups Collection Object | GroupCriterion Object, GroupCriteria Collection Object | List Object | LookupTable Collection Object | Month Object, Months Collection Object | Month Object, Months Collection Object | OutlineCode Object, OutlineCodes Collection Object | PayRate Object, PayRates Collection Object | Period Object | Profile Object, Profiles Collection Object | Project Object, Projects Collection Object | Resource Object, Resources Collection Object | SplitPart Object, SplitParts Collection Object | Subproject Object, Subprojects Collection Object | Table Object, Tables Collection Object | TableField Object, TableFields Collection Object | Task Object, Tasks Collection Object | TaskDependency Object, TaskDependencies Collection Object | TimeScaleValue Object, TimeScaleValues Collection Object | View Object, Views Collection Object | ViewCombination Object, ViewsCombination Collection Object | ViewSingle Object, ViewsSingle Collection Object | WeekDay Object, WeekDays Collection Object | WeekDay Object, WeekDays Collection Object | Window Object, Windows Collection Object | Windows2 Collection Object | Year Object, Years Collection Object | Year Object, Years Collection Object

See Also | Add Method | Delete Method | Index Property | NumberOfResources Property | NumberOfTasks Property