Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selecting partial strings

Status
Not open for further replies.

Luis939

MIS
Feb 28, 2003
453
US
I have this code

ActiveCell.Value = Left(ActiveCell.Text, InStr(ActiveCell.Text, " ") - 1)

that allows me to search the string from the left until you find a blank " ", but how would i specify that i want to search only until the second blank or 3rd etc, Thanks!
 
Function UpTillSpace(s As String, n As Integer) As String
Dim p As Integer, i As Integer
p = 0: i = 1
Do While i <= n
p = InStr(p + 1, s, &quot; &quot;)
If p = 0 Then
i = n
p = Len(s) + 1
End If
i = i + 1
Loop
UpTillSpace = Left(s, p - 1)
End Function Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top