vba SpecialCells(Type,Value) 参数说明

Range.SpecialCells 方法可以返回一个 Range 对象,该对象代表与指定类型和值匹配的所有单元格。 其语法如下: 表达式.SpecialCells(Type,Value) 其Type参数的可选XlCellType常量及对应值如下表:

XlCellType 常量

说明

xlCellTypeAllFormatConditions

-4172

任意格式单元格

xlCellTypeAllValidation

-4174

含有验证条件的单元格

xlCellTypeBlanks

4

空单元格

xlCellTypeComments

-4144

含有注释的单元格

xlCellTypeConstants

2

含有常量的单元格

xlCellTypeFormulas

-4123

含有公式的单元格

xlCellTypeLastCell

11

已用区域中的最后一个单元格

xlCellTypeSameFormatConditions

-4173

含有相同格式的单元格

xlCellTypeSameValidation

-4175

含有相同验证条件的单元格

xlCellTypeVisible

12

所有可见单元格

当Type参数为 xlCellTypeConstants 或 xlCellTypeFormulas时,Value参数有4种XlSpecialCellsValue 常量可选,见下表:

XlSpecialCellsValue 常量

说明

xlErrors

16

错误值

xlLogical

4

逻辑值

xlNumbers

1

数字

xlTextValues

2

文本

如下SpecialCells(xlCellTypeConstants,23)语句中的23=16+4+1+2,即表示定位的常量包含4种类型的单元格:错误值+逻辑值+数字+文本

  1. Sub 定位常量()
  2. Range("a:a").SpecialCells(xlCellTypeConstants, 23).Select
  3. End Sub

如只要定位常量错误值及逻辑值(即16+4=20),则采用如下代码:

  1. Sub test1()
  2. Range("a:a").SpecialCells(xlCellTypeConstants, 20).Select

原文:http://blog.csdn.net/nidehong/article/details/6669841

posted @ 2013-12-27 21:25  梦想(胡大利)  阅读(24702)  评论(0编辑  收藏  举报