CountIf-如何转义特殊字符(尖括号) [英] CountIf - How to escape special characters (angle brackets)
问题描述
我正在尝试使用VBA计算Excel电子表格中特定单元格值出现的次数.单元格值是XML标记,并且函数将尖括号解释为小于/大于.这些字符如何转义?
I am trying to count the number of times a specific cell value occurs within an Excel spreadsheet, using VBA. The cell value is an XML tag, and the angle brackets are interpreted by the function as less than/more than. How can these characters be escaped?
微软说:
可以将通配符,问号(?)和星号(*)用作条件.问号可以匹配任何单个字符;星号可以匹配任何字符序列.如果要查找实际的问号或星号,请在字符前输入波浪号(〜)."
"You can use the wildcard characters, question mark (?) and asterisk (*), for the criteria. A question mark matches any single character; an asterisk matches any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) before the character."
但这似乎不适用于我.我的代码:
But this does not seem to work for me. My code:
count = WorksheetFunction.CountIf(Sheets("Sheet1").Range("A:A"), "<element>")
推荐答案
由于应将等号视为评估值,因此应将方括号作为字符串的一部分读取.
This should push the bracket to be read as part of the string since the equals sign is read as the evaluation.
count = WorksheetFunction.CountIf(Sheets("Sheet1").Range("A:A"), "=<element>")
这篇关于CountIf-如何转义特殊字符(尖括号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!