Count Property

Applies To

All collections.

Description

Returns the number of items in the collection. Read-only.

For help about using the Count worksheet function in Visual Basic, see "Using Worksheet Functions in Visual Basic" in online Help.

Example

This example displays the number of menus on the active menu bar.


MsgBox "The active menu bar contains " & _
    ActiveMenuBar.Menus.Count & " menus."

This example displays the number of columns in the selection on Sheet1. The code also tests for a multi-area selection; if one exists, the code loops on the areas of the multi-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.


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