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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM