Check if cell contains part of a string

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
I have a cell which has a formula result in it which at the moment is like this;

"E0700-1500"

That cell can have any one of a number of different values in different formats, but I'm trying to find a formula that can tell me if the cell value has a hyphen in it.

I thought doing something like *-* would do it but it doesn't so does anyone have an idea?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try:
Code:
=ISNUMBER(FIND("-",A1))
 
Upvote 0
Joe4,

Thanks - works a treat!

Can I add text though?

So if the result is TRUE I need "Available" and if False "Unavailable"

Thanks in advance and sorry, formulas are not my forte!
 
Upvote 0
Sure, just wrap it in an IF statement. Since the formula already returns TRUE/FALSE, that is really easy:
Code:
=[COLOR=#ff0000]IF([/COLOR][COLOR=#0000ff]ISNUMBER(FIND("-",A1))[/COLOR][COLOR=#333333],[/COLOR][COLOR=#ff0000]"Available","Unavailable")[/COLOR]
 
Upvote 0
Thanks Joe4,

My interest has been sparked!

So how about if I wanted to combine ISNUMBER and ISTEXT? I've tried this but it doesn't work;

=IF(OR(ISNUMBER(FIND("-",J5)),ISTEXT(J5="NTE")),"Available","Unavailable")
 
Upvote 0
You wouldn't use ISTEXT. You have misunderstood how it works. Note that "-" is just as much of a string as "NTE" is!

If you break it down, we are first using the FIND function to find where the hyphen resides in cell J5.
If it finds it, it returns the number of the position it resides in.
If it does not find it, it returns an error.
So, we then use ISNUMBER to see if that result is a number (if it is, then it means we found a a hyphen, if it is not, that means that we do not find one).

So, if you wanted to check to see if your cell contains a hyphen OR the text"NTE", you would use:
Code:
[COLOR=#333333]=IF(OR(ISNUMBER(FIND("-",J4)),[/COLOR][COLOR=#333333]ISNUMBER(FIND("NTE",J4)))[/COLOR][COLOR=#333333],"Available","Unavailable")[/COLOR]
 
Upvote 0
Now I understand!

Thanks - everyday is a day at school!
 
Upvote 0
You are welcome!
Glad I was able to help.
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,500
Members
449,090
Latest member
RandomExceller01

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