How to extract partial string onto another cell if conditions are met?

fleabot

New Member
Joined
Jan 11, 2018
Messages
3
Hi :)

I was wondering if someone could help me with a formula I am having a hard time coming up with:

I have an excel sheet with various recipient addresses. The recipient name column, say column A, will look something similar to "Ship to business #1584" or "Ship to business #1224" or "Jane Doe". I need to extract the 4 digits after # onto another column, say column C. I think I have the formula to that which is =REPLACE(A2,1,FIND("#",A2),"") . However, for all the recipient names that DO NOT have the text "ship to business", I need it to come back as 8119 in column C. How would I create that formula to extract the 4 digits but also include the 8119 if there is no business # on the recipient name? I included sample table below:


recipient name (column A)recipient address (column B)identifier (Column C)
Jane Doe123 Hello Panda Lane8119
C/O Business #1234456 Kitty Paw Street1234
C/O Business #2456789 Chihiro Court2456
Michael Smith7655 Forest Lane8119

<tbody>
</tbody>

I appreciate any help!
Thank you

 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
hi - welcome to the board

=IF(ISNUMBER(FIND("#",A1)),--REPLACE(A1,1,FIND("#",A1),""),8119)

I added the -- in front of the replace() to coerce what would otherwise be a text string to a number - this may or may not be important.
 
Upvote 0
hi - welcome to the board

=IF(ISNUMBER(FIND("#",A1)),--REPLACE(A1,1,FIND("#",A1),""),8119)

I added the -- in front of the replace() to coerce what would otherwise be a text string to a number - this may or may not be important.

Thank you for replying me! I tried that formula and it works great. Although I have one worry, is there a way to make sure only recipient names that contains the text "C/O Business" in the cell show up with the 4 digit #? For example, if the recipient name was Jane Doe #123 , the result would still need to come back as 8119 because it does not contain "C/O Business" in its name. I hope that makes sense.
 
Upvote 0
"...is there a way to make sure only recipient names that contains the text "C/O Business" in the cell show up with the 4 digit #?"

Will depend on how variable the data entry rules are. Given your example data, this would do it:

=IF(ISNUMBER(FIND("C/O Business #",A1)),--REPLACE(A1,1,FIND("#",A1),""),8119)
 
Upvote 0
Here is another formula for you to consider...

=IFERROR(0+MID(A1,SEARCH("C/O Business #",A1)+14,4),8119)
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,581
Members
449,089
Latest member
Motoracer88

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