gpt4 book ai didi

excel - VBA excel - 从 excel 调用函数

转载 作者:行者123 更新时间:2023-12-04 21:51:25 28 4
gpt4 key购买 nike

我编写了一个 VBA 程序来删除元音。我无法从 excel 调用该函数。我收到 #NAME 错误。下面的代码

Function REMOVEVOWELS(Txt) As String
'Removes all vowels from the Txt argument
Dim i As Long
REMOVEVOWELS = ""
For i = 1 To Len(Txt)
If Not UCase(Mid(Txt, i, 1)) Like "(AEIOU)" Then
REMOVEVOWELS = REMOVEVOWELS & Mid(Txt, i, 1)
End If
Next i
End Function

Tim Stack 插入的代码标签

最佳答案

重写、测试和工作!将其插入模块顶部

Function REMOVEVOWELS(Txt) As String
'Removes all vowels from the Txt argument
Dim i As Long
For i = 1 To Len(Txt)
If Mid(Txt, i, 1) Like "[AEIOU]" Then
Txt = Replace(Txt, Mid(Txt, i, 1), "")
End If
Next i
REMOVEVOWELS = Txt
End Function

编辑

更优雅的解决方案。
Function REMOVEVOWELS(Txt) As String
'Removes all vowels from the Txt argument
Vowels = Array("A", "E", "I", "O", "U")

For Each a In Vowels
Txt = Replace(Txt, a, "")
Next a
REMOVEVOWELS = Txt
End Function

关于excel - VBA excel - 从 excel 调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53517274/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com