Excel Function Programming Question

Status
Not open for further replies.

hatfarm

Ars Scholae Palatinae
1,134
Subscriptor++
Hello all. I'm trying to help my brother out with a spreadsheet for work. He's got a list of customers that give him strings for their company name, and he just wants to pull out one word of the name. For instance, a string might contain "AwesomeSauce Corp of America Limited" and he just wants to have "AwesomeSauce" for his purposes. This is fairly easy to handle, he just has a function like such:

=IF(ISERROR(SEARCH("AwesomeSauce",A50,1)),"","AwesomeSauce")

This will print "AwesomeSauce" in the field if AwesomeSauce exists in the string given. However, there are hundreds of companies he gets in and right now I gave him a nested if that works, but is just a mess and there is probably something better. I thought about making a macro for loop that just goes through a list, but I wasn't sure if there was something better that someone might know of. It's difficult to Google this sort of thing because I don't really know what I would search for specifically. Here's what I'm thinking it should do:

Have an array of company names in column Q or something, and then have a function that just searches for each string and puts whichever string is found in the slot, but without a giant number of if statements nested.

This is confusing enough, imagine hundreds of these statements nested.
=IF(ISERROR(SEARCH("AwesomeSauce",A50,1)),=IF(ISERROR(SEARCH("SuperSweet",A50,1)),"","SuperSweet") ,"AwesomeSauce")

I will love you forever if you can help. Thanks.
 

upstateal

Ars Scholae Palatinae
1,013
If your company name is in column A (in this case, row 1 is the header and the data starts in row 2):
Code:
=LEFT(A2,SEARCH(" ",A2))

SEARCH(" ",A2) returns the first instance of the space character in the string found in cell A2. Left(A2,X) returns the left X characters in cell A2. So once you know where the space is, just count that many characters from the beginning of the string.

Net result: You get the first word in each company's name.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
Separate sheet ith two columns, longname, shortname,

Do a vlookup, if it fails present "unknown" and add an easy way to insert another entry (optionally, have a fallback function that scans the short names for sub string matches.

I would suggest writing this in VBA[1], it will be far easier to read and maintain than a massive embedded formulae.

This is all of course in lieu of getting a simple CRM, I really ope he has back ups of this sheet...

1. Yes I did throw up a little there.
 
Status
Not open for further replies.