将String转换为大写的函数 [英] function to convert String to upper case

查看:371
本文介绍了将String转换为大写的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用VBA中的String.ToUpper()方法使我编写的用户定义函数全部大写返回它的值.当我尝试在excel中使用UDF时,出现一个编译器错误,仅突出显示了我的UDF的顶行:

I have been trying to make a user defined function I wrote return it's value in all upper case, using the String.ToUpper() method in VBA. When I try to use my UDF in excel, I get a compiler error that just highlights the top line of my 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

该代码可以很好地删除特殊字符,但我希望它也可以将输入的String转换为大写.

The code works fine to remove special characters, but I would like it to also convert the inputted String to upper case.

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

I started receiving this error when I tried to add:

sInput = sInput.ToUpper()

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

If this code is commented out, my UDF works, but without returning the inputted string in all Upper.

推荐答案

只是错误的函数.你想要

Just the wrong function. You want

sInput = UCase(sInput)

希望有帮助

这篇关于将String转换为大写的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆