This documentation is archived and is not being maintained.

Count Property [Excel 2003 VBA Language Reference]

Office 2003

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

expression.Count

expression Required. An expression that returns one of the above objects.

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

expression.Count

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

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.

Sub DisplayColumnCount()
    Dim iAreaCount As Integer
    Dim i As Integer

    Worksheets("Sheet1").Activate
    iAreaCount = Selection.Areas.Count

    If iAreaCount <= 1 Then
        MsgBox "The selection contains " & Selection.Columns.Count & " columns."
    Else
        For i = 1 To iAreaCount
            MsgBox "Area " & i & " of the selection contains " & _
            Selection.Areas(i).Columns.Count & " columns."
        Next i
    End If
End Sub
		

This example makes the last character in cell A1 a superscript character.

Sub MakeSuperscript()
    Dim n As Integer

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


Applies to | AddIns Collection Object | Adjustments Object | AllowEditRanges Collection | Areas Collection | Axes Collection Object | Borders Collection | CalculatedFields Collection Object | CalculatedItems Collection Object | CalculatedMembers Collection | Characters Object | ChartGroups Collection | ChartObjects Collection Object | Charts Collection | Comments Collection Object | CubeFields Collection Object | CustomProperties Collection | CustomViews Collection Object | DataLabels Collection Object | DiagramNodeChildren Collection | DiagramNodes Collection | Dialogs Collection Object | Filters Collection Object | FormatConditions Collection Object | GroupShapes Collection Object | HPageBreaks Collection Object | Hyperlinks Collection | LegendEntries Collection Object | ListColumns Collection | ListObjects Collection | ListRows Collection | Names Collection Object | ODBCErrors Collection Object | OLEDBErrors Collection Object | OLEObjects Collection Object | Panes Collection Object | Parameters Collection Object | Phonetics Collection Object | PivotCaches Collection Object | PivotFields Collection Object | PivotFormulas Collection Object | PivotItemList Collection | PivotItems Collection Object | PivotTables Collection Object | Points Collection Object | PublishObjects Collection Object | QueryTables Collection Object | Range Collection | RecentFiles Collection Object | Scenarios Collection Object | SeriesCollection Collection Object | ShapeNodes Collection Object | ShapeRange Collection | Shapes Collection | Sheets Collection Object | SmartTagActions Collection | SmartTagRecognizers Collection | SmartTags Collection | Styles Collection | Trendlines Collection Object | UsedObjects Collection | UserAccessList Collection | VPageBreaks Collection Object | Watches Collection | Windows Collection Object | Workbooks Collection | Worksheets Collection | XmlMaps Collection | XmlNamespaces Collection | XmlSchemas Collection


Show: