silentwolf
Well-known Member
- Joined
- May 14, 2008
- Messages
- 1,216
- Office Version
- 2016
Hi guys,
I would like to split text in vba
So the above code splits string into an array.
But as I don't know the size of the array if the "The sentence is" like this then I will not have an array with varWoerter(3)
and it throughs an error.
I tried to catch it with the above code but in both ways I did not be able to work it out.
Mybe someone can tell me?
I know with ubound I find the last string in the array but if I don't know how long the array is in the first place then it does not work.
The reason behind this is I like to get some information out of the text but don't need to have a longer text split all the way.
Maximum to four
so varWoerter(3)
Thanks for your help!
I would like to split text in vba
VBA Code:
Function ViertesWort(varText As Variant)
Dim varWoerter As Variant
varWoerter = Split(varText, " ")
' ViertesWort = varWoerter(3)
' If varWoerter(3) = "" Then
' Debug.Print "Es ist leer"
' End If
'Also wrong
If IsNull(varWoerter(3)) Then
Debug.Print "Leer"
End If
End Function
So the above code splits string into an array.
But as I don't know the size of the array if the "The sentence is" like this then I will not have an array with varWoerter(3)
and it throughs an error.
I tried to catch it with the above code but in both ways I did not be able to work it out.
Mybe someone can tell me?
I know with ubound I find the last string in the array but if I don't know how long the array is in the first place then it does not work.
The reason behind this is I like to get some information out of the text but don't need to have a longer text split all the way.
Maximum to four
so varWoerter(3)
Thanks for your help!