问题
Let's say I have this variable:
word = "habit"
which command in VBA will allow me to count how many characters are there in this variable (in my case it's 5).
Important: the variable "word" contains only one word, no spaces, but may have contain numbers and hyphens.
回答1:
Do you mean counting the number of characters in a string? That's very simple
Dim strWord As String
Dim lngNumberOfCharacters as Long
strWord = "habit"
lngNumberOfCharacters = Len(strWord)
Debug.Print lngNumberOfCharacters
回答2:
Len(word)
Although that's not what your question title asks =)
回答3:
Len is what you want.
word = "habit"
length = Len(word)
回答4:
Use the Len function
length = Len(myString)
回答5:
Try this:
word = "habit"
findchar = 'b"
replacechar = ""
charactercount = len(word) - len(replace(word,findchar,replacechar))
来源:https://stackoverflow.com/questions/1725089/which-command-in-vba-can-count-the-number-of-characters-in-a-string-variable