Excel) (Areas.Count 属性

返回一个 Long 值,它代表集合中对象的数量。

语法

表达式计数

表达 一个代表 Areas 对象的变量。

示例

此示例显示 Sheet1 上所选范围内中的列数。 代码还将检测选定区域中是否包含多个子区域;如果包含,则对多重选定区域中每个子区域进行循环。

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

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。