IF Based On Word Count in Excel - 2388

If you like this content, please consider visiting the video on YouTube and subscribe to the MrExcel Channel to show your support!
This video has been published on Feb 22, 2021.
Nas T has to convert sport names to a 4-letter abbreviation. If the sport name has one word, then use the left four characters. But, if the sport name has two words, use the left 3 letters from the first word followed by the first letter from the second word. AND... Nas says we have to use the IF formula. My solution includes some LEFT, MID, IFERROR, FIND functions. Also in this episode: Flash Fill.
maxresdefault.jpg


Transcript of the video:
Learn Excel from MrExcel Podcast episode 2388.
IF based on word count.
Hey, welcome back to MrExcel netcast.
I am Bill Jelen.
Today’s question from Nas: He has a column of sports names.
If the sports name is a single word, we need the left 4 characters of the sport name. But if it's 2 words, such as ice hockey or auto racing, then the first 3 letters of the first word and the 1st letter of the second word.
Like ICEH or AUTR.
And then the thing that just makes me bristle.
You must use the IF function.
Why?
Why must we use the function?
Who is this?
Is this your manager is just a professor?
Is this homework?
What's going on?
Alright, so I'm going to ignore that IF requirement right now because I think that's a bad way to go using IF What I am going to do: I'm going to assume always that there are two words.
So, equal LEFT of the first word, comma three.
And then ampersand.
And the MID of A8.
Comma.
Where do I want to start?
I want to start.
I want to start right after the space.
So find a space in A8.
Plus one for a length of 1.
Like that.
And I'm going to get a #VALUE! error whenever there's a single word right?
Simple enough, but that's OK because I'm going to handle that #VALUE!
error by wrapping the whole thing in the IFERROR function So if there's not 2 words, then we know that we're going to be out here and we're just going to simply ask for the LEFT of A8 comma 4 like that.
Double click and copy that down.
In his example it was uppercase and maybe wrap the whole thing in UPPER.
I don't know if that's a requirement or not.
Alright, so beer pong B-E-E-P.
Works great.
Now, why is this requirement for using the IF function?
But if we really have to use the function, I guess we could do it.
We could say equal IF the LENgth of A8 is equal to the LENgth A8 minus any spaces.
That will tell you how many words there are.
Then we take the left of A8 comma four.
Otherwise the same formula I just used.
Essentially, the formula is a lot longer than I don't particularly like it because it's going to fail when someone does this.
If they type soccer space space space.
Then we're not going to get the fourth letter because it finds the space.
So this is a case where not using it actually is better than using IF.
And,.
I wonder why the professor or manager had this requirement of having to use the if function.
Maybe they were trying to prevent someone from just typing the whole thing or using Flash Fill.
Now that the great way to use Flash Fill.
I took field hockey something with two words and moved it up here to the top.
F-I-E-H.
And then Beer pong and then baseball.
So in my examples I give it enough examples to show it what the rules are.
And then back here.
Data, out on the far right side, Flash Fill, or just control E.
Press Ctrl+E and it does the right thing.
There you are.
Alright, so Nas, that's my way to do it.
Check out my book MrExcel 2020, Seeing Excel Clearly If you like these videos please, down below, Like, Subscribe and Ring that Bell.
Feel free to post any questions or comments down in the comments below.
I want to thank you for stopping by.
We will see next time for another netcast from MrExcel.
 

Forum statistics

Threads
1,223,666
Messages
6,173,665
Members
452,527
Latest member
ineedexcelhelptoday

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