我一直在尝试编写一个用户定义函数,使其返回大写字母的值,使用VBA中的String.ToUpper()
方法。当我尝试在Excel中使用我的UDF时,会出现编译器错误,只会突出显示我的UDF的顶部行:
Function removeSpecial(sInput As String) As String
以下是完整的代码:
Function removeSpecial(sInput As String) As String
Dim sSpecialChars As String
Dim i As Long
sSpecialChars = "\/:*?™""®<>|.&@# (_+`©~);-+=^$!,'" 'This is your list of characters to be removed
For i = 1 To Len(sSpecialChars)
sInput = Replace$(sInput, Mid$(sSpecialChars, i, 1), "")
Next
sInput = sInput.ToUpper()
removeSpecial = sInput
End Function
代码可以很好地删除特殊字符,但我希望它也可以将输入的字符串转换为大写字母。
当我试图添加以下内容时,开始收到此错误提示:
sInput = sInput.ToUpper()
如果注释掉这段代码,我的 UDF 就能工作,但是无法将输入的字符串全部转为大写。
sInput = UCase(sInput)
。 - Dmitry Pavliv