函数将String转换为大写

6 excel vba excel-vba excel-udf

我一直在尝试创建一个用户定义的函数,我使用String.ToUpper()VBA中的方法以大写的形式返回它的值.当我尝试在excel中使用我的UDF时,我得到一个编译器错误,只是突出显示了我的UDF的顶行:

Function removeSpecial(sInput As String) As String
Run Code Online (Sandbox Code Playgroud)

以下是完整的代码:

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
Run Code Online (Sandbox Code Playgroud)

代码可以正常删除特殊字符,但我希望它也将输入的字符串转换为大写字母.

我尝试添加时开始收到此错误:

sInput = sInput.ToUpper()
Run Code Online (Sandbox Code Playgroud)

如果此代码被注释掉,我的UDF可以正常工作,但不会返回所有Upper中输入的字符串.

小智 14

只是错误的功能.你要

sInput = UCase(sInput)
Run Code Online (Sandbox Code Playgroud)

希望有所帮助