title | keywords | f1_keywords | api_name | ms.assetid | ms.date | ms.localizationpriority | ||
---|---|---|---|---|---|---|---|---|
Areas.Count property (Excel) |
vbaxl10.chm197073 |
|
|
c3c91bed-d3dd-7ffd-94be-f61cc3b973b7 |
04/06/2019 |
medium |
Returns a Long value that represents the number of objects in the collection.
expression.Count
expression A variable that represents an Areas object.
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
[!includeSupport and feedback]