Extract Text to Left Before First Space and Return to Right Side (End) of Same String

seattletimebandit

Board Regular
Joined
Apr 11, 2013
Messages
69
Good day.

I have columns of analytical data, some have a leading letter(s) as part of the lab result (i.e., U, UJ, E, B, R), some have no letter.

There is a space between the letter and number:

U 0.042

I need to reverse the string:

0.042 U

If there is no letter (e.g., 0.042 or cell is blank), then just return the number or blank cell.

I've found many ways to do this, but it works only if there is a text w/a space. If there is no leading text/space, it chokes and returns an error (#VALUE!).

Thanks!
stb
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi,
would this UDF work for you?
Code:
Function ChangeText(ByVal strText As String) As String
    Dim intPos As Integer
    Dim strFB As String
    
    intPos = InStr(strText, " ")
    strFB = Left(strText, intPos)
    
    If intPos = 0 Then
        ChangeText = strText
    
    Else
        ChangeText = Mid(strText, intPos + 1) & " " & strFB
    End If
    
End Function

not sure how to do it in a formula but if you paste that code above into a module you could use this function to do hopefully what you are after.

HTH
 
Upvote 0
Somewhat clunky, but
=IF(I21="","",IF(ISNUMBER(FIND(" ",I21)),RIGHT(I21,LEN(I21)-FIND(" ",I21))&" " &LEFT(I21,FIND(" ",I21)),I21))
 
Upvote 0
Thanks Fluff, that worked as intended.

Silentwolf, thanks to you too. I'll give yours a go later. I've never called a function from a module before. Need me some learnin'.

stb
 
Upvote 0
Hi,

How about this simpler formula solution:


Book1
AB
1U 0.0420.042 U
20.0420.042
3
4UJ 0.0420.042 UJ
Sheet639
Cell Formulas
RangeFormula
B1=MID(A1&" "&A1,FIND(" ",A1&" ")+1,LEN(A1))
 
Last edited:
Upvote 0
Somewhat clunky, but
=IF(I21="","",IF(ISNUMBER(FIND(" ",I21)),RIGHT(I21,LEN(I21)-FIND(" ",I21))&" " &LEFT(I21,FIND(" ",I21)),I21))
Less clunky (and I think it will work too)...

=MID(I21&" "&I21,FIND(" ",I21&" ")+1,LEN(I21))
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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