Data to the left of the first space

bobgrand

Board Regular
Joined
Apr 14, 2008
Messages
244
Office Version
  1. 365
Platform
  1. Windows
Hello all,
I have a column of product codes. The beginning part of the code is what we call the prefix. This can be anywhere from 2 to 6 characters in length followed by a space. I need to take the prefix part of the product code and put them in a separate column. I tried a couple different formulas but was not getting the right result.

Any help would be greatly appreciated

Have a great day
Bob
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Assuming Cell A1 has ABCD 1234. Enter the following in B1

=MID(A1,1,FIND(" ",A1))

This should give you ABCD
 
Last edited:
Upvote 0
You might want to subtract 1 from the result of Find.
Otherwise you get "ABCD " <-including the space

=MID(A1,1,FIND(" ",A1)-1)
 
Upvote 0
Hello all,

Many years ago I started this thread and now I need to add to it. Finding the data to the left of the first space has worked like a charm. I am now finding data where there is no space and the result is giving me #VALUE !.

I can't figure out the formula.

If there is no space in the characters in cell A1 put that data in B1 otherwise do this ~~> =MID(A1,1,FIND(" ",A1)-1)

Any help would be greatly appreciated.

Thanks
Bob
 
Upvote 0
You can just add a space to the end of A1 before looking for it:

=LEFT(A1,FIND(" ",A1&" ")-1)
 
Upvote 0
I don't think just adding a space is an option. There are hundreds of items scattered in different files where the spaces have been removed.
 
Upvote 0
Hi,

Adding the " " (SPACE) in the formula as suggested by Rory is to Avoid the #VALUE error when the Cell the formula is looking at doesn't Already have a Space within the Text String.
If No Space was in the original Text String, the formula will return Whatever is in that cell. Try it.
 
Last edited:
Upvote 0
I am now finding data where there is no space and the result is giving me #VALUE !.

I can't figure out the formula.
[/COLOR]
If I understand correctly, you have the same values, but the space after the prefix has been removed. If that is correct, what are the prefixes (letters only?) and what comes after them (numbers only?)?
 
Upvote 0
I am now finding data where there is no space and the result is giving me #VALUE !.

If there is no space in the characters in cell A1 put that data in B1 otherwise do this ~~> =MID(A1,1,FIND(" ",A1)-1)

Bob

Hi Rick, I believe if there's no Space, OP just want whatever is in the cell...might be wrong.
 
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,785
Members
449,095
Latest member
m_smith_solihull

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