Share via


Areas.Count Property

Excel Developer Reference

Returns a Long value that represents the number of objects in the collection.

Syntax

expression.Count

expression   A variable that represents an Areas object.

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.

Visual Basic for Applications
  Sub DisplayColumnCount()
    Dim iAreaCount As Integer
    Dim i As Integer
Worksheets("Sheet1").Activate
iAreaCount = Selection.Areas.<strong>Count</strong>

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

End Sub

See Also