AllExperts > Excel 
Search      
Excel
Volunteer
Answers to thousands of questions
 Home · More Excel Questions · Answer Library  · Encyclopedia ·
More Excel Answers
Question Library

Ask a question about Excel
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Richard Roberts
Expertise
Can assist you in most areas of Excel, have been working with it for about 15 years in many types of applications, but primarily in financial and accounting applications. I am a CPA and many client or client problems have necessitated the use of excel. I am not an expert in charting, macros, or pivot tables.

Experience
Have been working with Excel for about 15 years primarily in accounting and financial areas.

Education/Credentials
BA, CPA

 
   

You are here:  Experts > Computing/Technology > Microsoft Software > Excel > If statement

Excel - If statement


Expert: Richard Roberts - 7/10/2009

Question
I need an IF Statement for certain numbers in a cell.  Example: Cell B2 has MJ244F001057 in it.  I need a statement that says If B2 contains 1057 then E2 else E2-7.

Answer
Debbie

You can use the search feature to identify whether the cell contains 1057.  the search will tell you what position the number starts, so if it tell you a position of 9, then you know it is there and starts at the 9th position in the text string.  If 1057 is not there then it returns the error message   #VALUE!

The search formula looks like +SEARCH(1057,B5)
this says look in cell B5 and tell me the position that 1057 start in.

You can combine this formula with the IF formula to produce the result you want.  For example.

=IF(ISERROR(SEARCH(1057,B5)>0),E2-7,E2)

This formula says if the result of the search is an ERROR meaning the 1057 is not located within the cell B5, the use +E2-7.  If the search formula results in a number greater than 0, then use E2.

Of course your formula doesn't have to refer specifically to 1057, it can refer to a cell that contains your criteria, so you could write the formula  

=IF(ISERROR(SEARCH(F2,B5)>0),E2-7,E2)

Where F2 contains 1057

If you set the formula up this way, you can change the criteria easily by merely changing the data in F2.

Hope this helps

Richard  

Ask a Question


 
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.