Domanda

I want to separate string after word "and". I use to do this, I write below function

Public Function find(separate_text) As Variant
 Dim i As Integer
 Dim text As String
 text = CStr(separate_text)
 ReDim returned(InStr(text, "and") To Len(CStr(text))) As Variant

 For i = InStr(CStr(text), "and") To Len(CStr(text)) - 4
     returned(i) = Mid(text, i + 4, 1)
 Next i
 find = returned
End Function

When I want call it:

MsgBox CStr(find(example))

It's cause 13 error (mismatch). Where's the problem?

È stato utile?

Soluzione

Try this. if you want the first part of the separate_text to be returned, return splittext(0) in the third line

Public Function MyFind(separate_text As String) As String

splittext = Split(separate_text, "and")

MyFind = LTrim(splittext(1))

End Function
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top