处理删除连字符和非连字符的两种方法
Sub Test1()
Dim StrTest As String
StrTest = "I have a hypen-somewhere"
If InStr(StrTest, "-") > 0 Then
MsgBox Left$(StrTest, InStr(StrTest, "-") - 1)
Else
MsgBox "Not found"
End If
End Sub
Sub Test2()
Dim StrTest As String
Dim vString
StrTest = "I have a hypen-somewhere"
vString = Split(StrTest, "-")
If UBound(vString) > 0 Then
MsgBox vString(0)
Else
MsgBox "Not found"
End If
End Sub
Run Code Online (Sandbox Code Playgroud)