How to Get or Display Array Value of Split(TextString) ?

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
684
Hello

Would like to Get or Display the Array Value of Splited(TextString)
VBA Code:
Sub SplitWords()
Dim TextStrng As String
Dim Result() As String
TextStrng = "The Quick Brown Fox Jumps Over The Lazy Dog"
Result() = Split(TextStrng)
End Sub
with above code we know the following result
Result(0) = "The"
Result(1) = "Quick"
Result(2) = "Brown"
Result(3) = "Fox"
Result(4) = "Jumps"
Result(5) = "Over"
Result(6) = "The"
Result(7) = "Lazy"
Result(8) = "Dog"

What i am interested in if i type the string "Jumps" then I should get FindArray(Result) or Array value as 4 . Hope i am making my statement clear.
The below returns Boolean True although IsInarray defined as Long
VBA Code:
Sub Test
Dim TextStrng As String
Dim Result() As String
TextStrng = "The Quick Brown Fox Jumps Over The Lazy Dog"
Result() = Split(TextStrng)
MsgBox (IsInArray("Jumps", Result) > -1)
End Sub

Function IsInArray(stringToBeFound As String, arr As Variant) As Long
  Dim i As Long
  IsInArray = -1

  For i = LBound(arr) To UBound(arr)
    If StrComp(stringToBeFound, arr(i), vbTextCompare) = 0 Then
      IsInArray = i
      Exit For
    End If
  Next i
End Function

Will appreciate your valuable inputs

Thanks
NimishK
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
How about
VBA Code:
MsgBox (IsInArray("Jumps", Result))
 
Upvote 0
Solution
Fantastic Fluff indeed this was really quicker response to resolve. ?

Somehow i forgot the values of Boolean. No wonder it displayed "True" My Bad luck?

Thanks Anyways
NimishK
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,216,750
Messages
6,132,503
Members
449,730
Latest member
SeanHT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top