Which command in VBA can count the number of chara

2020-03-12 10:58发布

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.

5条回答
迷人小祖宗
2楼-- · 2020-03-12 11:21

Len is what you want.

word = "habit"  
length = Len(word)
查看更多
别忘想泡老子
3楼-- · 2020-03-12 11:22

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
查看更多
Juvenile、少年°
4楼-- · 2020-03-12 11:38

Try this:

word = "habit"
findchar = 'b"
replacechar = ""
charactercount = len(word) - len(replace(word,findchar,replacechar))
查看更多
干净又极端
5楼-- · 2020-03-12 11:42
Len(word)

Although that's not what your question title asks =)

查看更多
▲ chillily
6楼-- · 2020-03-12 11:42

Use the Len function

length = Len(myString)
查看更多
登录 后发表回答