How can I check if a string only contains letters?

后端 未结 4 1772
耶瑟儿~
耶瑟儿~ 2020-12-06 17:52

I\'m using a function that allows me to review a string of text and evaluate if it is composed of letters. It is housed in a module called \"General\". The general module

4条回答
  •  盖世英雄少女心
    2020-12-06 18:37

    Why don't you use regular expressions instead? Then there's no loops involved:

    Public Function IsAlpha(strValue As String) As Boolean
        IsAlpha = strValue Like WorksheetFunction.Rept("[a-zA-Z]", Len(strValue))
    End Function
    

    Also, when you create a User-Defined Function (UDF) you need to ensure that the return value is assigned to the name of the actual function, in this case IsAlpha - not IsLetter otherwise the value will never be passed back.

提交回复
热议问题