Dim Start As Integer
Start= InStr(1,MyString,"K",vbTextCompare)
If Start Then
Debug.Print Mid$(MyString,Start,InStr(Start,MyString," "-Start)
End If
You could also use Split() twice: The first time on "K" and take the 2nd element, if one exists, and then Split again on a Space, and take the first element.
The easiest way - maybe not the most efficient is:
Dim j As Integer
Dim sData As String
Dim vData As Variant
'Test data
sData = "This is a test of the K1212121|0 string that has another K334343 value."
'Get the array of space delimited words into an array - this assumes data is split by spaces!
vData = Split(sData, " "
'Check for more than one 'K' value - this assumes your K values start the word
For j = 0 To UBound(vData)
If Left(vData(j), 1) = "K" Then
'Here is your value vData(j)
sData = vData(j)
End If
Next j
Then just use the Right command - you can check for beginning or ending:
If Left(vData(j), 1) = "K" Or Right(vData(j), 1) = "K"
-------------------------- Code added
Dim j As Integer
Dim sData As String
Dim vData As Variant
'Test data
sData = "This is a test of the K1212121|0 string that has another K334343 value."
'Get the array of space delimited words into an array - this assumes data is split by spaces!
vData = Split(sData, " "
'Check for more than one 'K' value - this assumes your K values start the word
For j = 0 To UBound(vData)
If Left(vData(j), 1) = "K" Or Right(vData(j), 1) = "K" Then
'Here is your value vData(j)
sData = vData(j)
End If
Next j
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.