Skip to content

Latest commit

 

History

History
56 lines (37 loc) · 1.61 KB

Excel.Range.Count.md

File metadata and controls

56 lines (37 loc) · 1.61 KB
title keywords f1_keywords api_name ms.assetid ms.date ms.localizationpriority
Range.Count property (Excel)
vbaxl10.chm144107
vbaxl10.chm144107
Excel.Range.Count
080cbbe7-056f-b21c-9004-171a6acce664
05/10/2019
medium

Range.Count property (Excel)

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

Syntax

expression.Count

expression A variable that represents a Range object.

Remarks

The Count property is functionally the same as the CountLarge property, except that the Count property will generate an overflow error if the specified range has more than 2,147,483,647 cells (one less than 2,048 columns). The CountLarge property, however, can handle ranges up to the maximum size for a worksheet, which is 17,179,869,184 cells.

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

[!includeSupport and feedback]