[英]Check if cell is only a-z excel
I would like to be sure that all my cell contain only characters (AZ/az). 我想确保我所有的单元格只包含字符(AZ / az)。 I want to be sure there isn't any symbol, number or anything else. 我想确保没有任何符号,数字或其他任何东西。 Any tips? 有小费吗?
For example I have this "Š". 例如,我有这个“Š”。
As a VBA function, the following should work: 作为VBA功能,以下应该起作用:
Option Compare Binary
Function LettersOnly(S As String) As Boolean
LettersOnly = Not S Like "*[!A-Za-z]*" And S <> ""
End Function
In using the function, S can be either an actual string, or a reference to the cell of concern. 在使用函数时,S可以是实际字符串,也可以是对所关注单元格的引用。
EDIT : Also, you want to be certain you have not set Option Compare Text
in your code. 编辑 :另外,您想确定自己没有在代码中设置“ Option Compare Text
。 The default is Option Compare Binary
which is what you want for this type of comparison. 默认值为“ Option Compare Binary
,这是您希望进行这种类型的比较。 I have added that to the code for completeness. 为了完整性,我已将其添加到代码中。
In your new module, create a new function like this: 在新模块中,创建一个新函数,如下所示:
Function IsAToZOnly(inputStr As String) As Boolean Dim pattern As String: pattern = "^[A-Za-z]*$" Dim regEx As New RegExp regEx.pattern = pattern IsAToZOnly = regEx.Test(inputStr) End Function
Use the new function in your worksheet: 在工作表中使用新功能:
=IsAToZOnly(A1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.