[英]Understanding the syntax of "special cells" in Excel VBA
我的代码的一部分如下所示:
With Selection
Set ConstantCell = .SpecialCells(xlCellTypeConstants, xlNumber)
Set FormulaCell = .SpecialCells(xltypeformulas, 21)
End With
它是宏的一部分,用于为包含不同类型数据的单元格着色。 我明白这部分的作用,但我想问的是21
代表什么? 我发现在这个公式的语法中它代表了一些值,我认为它只会选择具有公式且等于 21 的单元格,但当我运行整个宏时情况并非如此。
好像:
Set FormulaCell = .SpecialCells(xlCellTypeFormulas, 21)
是相同的:
Set FormulaCell = .SpecialCells(xlCellTypeFormulas, xlErrors + xlLogical + xlNumbers)
因为:
如果Type是xlCellTypeConstants或xlCellTypeFormulas ,则此参数用于确定要包含在结果中的单元格类型。 这些值可以加在一起以返回一种以上的类型。 默认是选择所有常量或公式,不管是什么类型。
和:
XlSpecialCellsValue常量
xlErrors +16 xlLogical +4 xlTextValues +2 xlNumbers +1
在:
https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-specialcells-method-excel
(此外,在您的示例中, xlCellTypeFormulas
拼写错误。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.