Article ID: 152568
Article Last Modified on 10/10/2006
Function FindNthWord(WordStrg As Variant, occur)
' Declare variables where WordStrg is the string whose Nth word you
' want to extract and occur is the number of the word (or Nth word)
' you want to extract from the string.
Dim y, z As Integer
Dim WordSearch()
y = (Len(WordStrg) - (Len(Application.Substitute(WordStrg, " ", _
"")))) / 1
ReDim WordSearch(1 To (y + 1))
z = 1
For SearchLoop = 1 To y
z = (InStr(z, WordStrg, " "))
WordSearch(SearchLoop) = Left(WordStrg, z)
WordStrg = Application.Trim(Mid(WordStrg, z + 1))
z = 1
Next SearchLoop
WordSearch(y + 1) = WordStrg
' Assigns the result to the function.
FindNthWord = WordSearch(occur)
End Function
A1: For a comparison of Dow Jones B1:
A2: Industrial Averages and the price of this B2:
A3: stock over the same quarter, refer to the B3:
A4: next section of the worksheet. B4:
B1: =FindNthWord(A1,2)
A1: For a comparison of Dow Jones B1: a
A2: Industrial Averages and the price of this B2: Averages
A3: stock over the same quarter, refer to the B3: over
A4: next section of the worksheet. B4: section
176476 OFF: Office Assistant Not Answering Visual Basic Questions
Additional query words: 5.00a 5.00c 7.00a XL98 XL97 XL7 XL5 example XL
Keywords: kbdtacode kbhowto kbprogramming KB152568