Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CountIf - How to escape special characters (angle brackets)

Tags:

excel

vba

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?

Microsoft says:

"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>")
like image 760
user3341082 Avatar asked Sep 07 '25 15:09

user3341082


1 Answers

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>")
like image 193
DGulledge Avatar answered Sep 10 '25 20:09

DGulledge