Extract 2nd word of string

Cmacvp16

New Member
Joined
Aug 8, 2002
Messages
44
In excel I developed a formula to extract the second word of a text string.

Cell A1 = "The standard response"

Cell B1 = MID(A2, FIND(" ",A2,1)+1, FIND(" ",A2,FIND(" ",A2,1)+1)-(FIND(" ",A2,FIND(" ",A2,1)))) retruns "standard"

Can this be done in a select query in access. I do not have a "Find" function in access to determine the space location.

Thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Works great! One other question, how can I further split a string between a numeric value and a letter?

10,000u/ml split into "10,000" and "u/ml". The units can vary "u/ml", "mcg/ml", etc. so I need a general approach.

I thought I could use the InStr function with "Like[a-z]".
 
Upvote 0
I think that to do that sort of split you will need to write a custom function in VBA and call that.

Peter
 
Upvote 0
Yes, you could write a VBA function. Are you looking to split this into two separate fields or to simply put a space between your numeric value and your text?
 
Upvote 0
will the 10,000 need to be returned as a number or in the format "10,000"

peter
 
Upvote 0
Ok. The following two functions should be able to get your info for you. I have not added any data checking or error trapping to the code!!

Code:
Function GetNum(strIn As String) As Double
Dim j As Integer
j = 1
Do While j <> Len(strIn)
If Not IsNumeric(Mid(strIn, j, 1)) And Not Mid(strIn, j, 1) = "," And Not Mid(strIn, j, 1) = "." Then Exit Do
j = j + 1
Loop
GetNum = CDbl(Left(strIn, j - 1))
End Function


Function GetStr(strIn As String) As String
Dim j As Integer
j = 1
Do While j <> Len(strIn)
If Not IsNumeric(Mid(strIn, j, 1)) And Not Mid(strIn, j, 1) = "," And Not Mid(strIn, j, 1) = "." Then Exit Do
j = j + 1
Loop
GetStr = Right(strIn, Len(strIn) - j + 1)
End Function

Peter
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,266
Members
448,558
Latest member
aivin

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