Newbie: How to search a text string from right

F

Frank Krogh

I want to split text strings like this:

Given the text string "George W. S. Rogers" (cell A1)

the result should be "George W. S." (cell B1) and "Rogers" (C1)


Thanks for any suggestions.


Kind regards

Frank Krogh
 
J

JE McGimpsey

One way:

A1: =TRIM(LEFT(A1, FIND("$", SUBSTITUTE(A1," ", "$", LEN(A1) -
LEN(SUBSTITUTE(A1 ," ", ""))))))

B1: =TRIM(MID(A1,LEN(B1)+1,255))
 
D

Don Guillett

try instrrev to find .which may not be in older versions so you could use.

Function InStrRev(Strng As String, Char As String) As Integer
Dim Lngth As Integer, i As Integer
Lngth = Len(Strng)
For i = Lngth To 1 Step -1
If Mid(Strng, i, 1) = Char Then
InStrRev = i
Exit Function
End If
Next i
End Function
'Howard Groves cmmroom@ ddre.detroitdiesel.com

Public Function InstrBack(ByRef intStart As Integer, ByRef strCheck As
String, ByRef strFind As String) As Integer
'Another method of above
'RETURNS THE POSITION OF THE LAST OCCURRENCE OF A STRING WITHIN A STRING
Dim intCounter As Integer
InstrBack = 0
For intCounter = (Len(strCheck) + 1 - intStart) To 1 Step -1
If Mid$(strCheck, intCounter, 1) = strFind Then
InstrBack = intCounter
Exit Function
End If
Next intCounter
End Function

Public Function StrReverse(reverseString As String) As String
Dim i As Long
For i = Len(reverseString) To 1 Step -1
StrReverse = StrReverse & Mid(reverseString, i, 1)
Next i
End Function
 
F

Frank Krogh

Thank for the suggestion.

I don't understand which cell is actually referenced?
Should it be like this:

A1: "George W. S. Rogers"

B1 (first name): =TRIM(LEFT(A1, FIND("$", SUBSTITUTE(A1," ", "$",
LEN(A1) - LEN(SUBSTITUTE(A1 ," ", ""))))))

C1 (last name): =TRIM(MID(A1,LEN(B1)+1,255))
 
H

Harlan Grove

Frank Krogh said:
I want to split text strings like this:

Given the text string "George W. S. Rogers" (cell A1)

the result should be "George W. S." (cell B1) and "Rogers" (C1)
....

Another alternative,

B1:
=LEFT(A1,LOOKUP(2,1/(MID(A1,ROW(INDIRECT("1:1024")),1)=" "),
ROW(INDIRECT("1:1024")))-1)

C1:
=MID(A1,LOOKUP(2,1/(MID(A1,ROW(INDIRECT("1:1024")),1)=" "),
ROW(INDIRECT("1:1024")))+1,1024)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top