Count Property

Applies To

AddIns collection object, Adjustments object, Areas collection object, Axes collection object, Borders collection object, CalculatedFields collection object, CalculatedItems collection object, Characters object, ChartGroups collection object, ChartObjects collection object, Charts collection object, Comments collection object, CustomViews collection object, DataLabels collection object, Dialogs collection object, FormatConditions collection object, GroupShapes collection object, HPageBreaks collection object, Hyperlinks collection object, LegendEntries collection object, Names collection object, ODBCErrors collection object, OLEObjects collection object, Panes collection object, Parameters collection object, PivotCaches collection object, PivotFields collection object, PivotFormulas collection object, PivotItems collection object, PivotTables collection object, Points collection object, QueryTables collection object, Range object, RecentFiles collection object, Scenarios collection object, SeriesCollection collection object, ShapeNodes collection object, ShapeRange collection object, Shapes collection object, Sheets collection object, Styles collection object, Trendlines collection object, VPageBreaks collection object, Windows collection object, Workbooks collection object, Worksheets collection object.

Description

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

Example

This example displays the number of columns in the selection on Sheet1. The code also tests for a multiple-area selection; if one exists, the code loops on the areas of the multiple-area selection.

Worksheets("Sheet1").Activate
areaCount = Selection.Areas.Count
If areaCount <= 1 Then
    MsgBox "The selection contains " & _
        Selection.Columns.Count & " columns."
Else
    For i = 1 To areaCount
        MsgBox "Area " & i & " of the selection contains " & _
            Selection.Areas(i).Columns.Count & " columns."
    Next i
End If
This example makes the last character in cell A1 a superscript character.

n = Worksheets("Sheet1").Range("A1").Characters.Count
Worksheets("Sheet1").Range("A1").Characters(n, 1) _
    .Font.Superscript = True