gpt4 book ai didi

vba - 删除字符右侧所有内容的代码会出错

转载 作者:行者123 更新时间:2023-12-04 21:16:45 30 4
gpt4 key购买 nike

我厌倦了删除所有内容,包括 . . 的右侧例如 aaaaa.ntuthuh我得到 aaaaa
如果我粘贴 = Left(A1, Find(".", A1) - 1)在工作表的单元格中,公式可以正常工作,但在宏中我收到错误 Sub or Function not definedFind突出显示

谢谢

Sub Split()
Dim fName As String

fName = Left(A1, Find(".", A1) - 1)
ActiveSheet.Range("B1").Value = fName

' have also tyred: Range("A1").Value = "=Left(A1, Find(".", A1) - 1)" and: Range("A2").Formula = "=Left(A1, Find(".", A1) - 1)" but throws error "." is highlighted a "Expected end of statement"

End Sub

最佳答案

这是第三种选择:

Sub Splitt()
Dim fName As String
fName = Split(Range("A1").Value, ".")(0)
ActiveSheet.Range("B1").Value = fName
End Sub

关于vba - 删除字符右侧所有内容的代码会出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21787399/

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