Count Property

Returns the number of objects in the specified collection. Read-only Long.

expression.Count

*expression   * Required. An expression that returns one of the objects in the Applies To list.

Example

This example sets variables to the number of columns and the number of rows in the visible range on the active worksheet, and then formats the color of the cells in every other row.

Sub Format_Odd_Rows()
    Dim rngUsed
    Dim iUsedRows
    Dim iUsedColumns
    Dim shtActive
    Dim iCtr
    
    Set shtActive = Spreadsheet1.ActiveSheet
    
    ' Set a variable ot the used range of the active sheet.
    Set rngUsed = shtActive.UsedRange
    
    ' Get the count of used rows in the active sheet.
    iUsedRows = rngUsed.Rows.Count
    
    ' Get the count of used columns in the active sheet.
    iUsedColumns = rngUsed.Columns.Count
    
    ' Loop through every odd row in the used range.
    For iCtr = 1 To iUsedRows Step 2
    
        ' Color the background of the cells green.
        shtActive.Range(shtActive.Cells(iCtr, 1), shtActive. _
            Cells(iCtr, iUsedColumns)).Interior.ColorIndex = 43
    Next
End Sub

Applies to | AllGroupingDefs Collection Object | AllPageFields Collection Object | Borders Collection Object | ChAxes Collection | ChChartFields Object | ChCharts Collection | ChDataLabels Object | ChDataLabelsCollection Collection | ChErrorBarsCollection Object | ChLegendEntries Collection | ChPoints Collection | ChSegments Object | ChSelectionCollection Collection | ChSeriesCollection Collection Object | ChTrendlines Collection | Criteria Object | DataPages Collection Object | ElementExtensions Collection Object | Filters Collection Object | GroupingDefs Collection Object | GroupLevels Collection Object | Headings Object | ListObjects Collection | ListRows Collection | LookupRelationships Collection Object | LookupSchemaRelationships Collection Object | Names Collection | PageFields Collection Object | PageRelatedFields Collection Object | PageRowsources Collection Object | Panes Collection Object | ParameterValues Collection Object | PivotAggregates Collection Object | PivotAxisMembers Collection | PivotColumnMembers Collection | PivotFields Collection Object | PivotFieldSets Collection Object | PivotMemberProperties Collection | PivotMembers Collection Object | PivotPageMembers Collection | PivotResultGroupFields Collection | PivotResultMemberProperties Collection | PivotRowMembers Collection | PivotTotals Collection Object | Range Object | RecordsetDefs Collection Object | SchemaFields Collection Object | SchemaParameters Collection Object | SchemaProperties Object | SchemaRelatedFields Collection Object | SchemaRelationships Collection Object | SchemaRowsources Collection Object | Sheets Collection | SublistRelationships Collection Object | SublistSchemaRelationships Collection Object | Windows Collection Object | Workbooks Collection | Worksheets Collection Object | XmlDataBindings Collection | XmlMaps Collection

See Also | Item Property