Home

Formula Help

%3CLINGO-SUB%20id%3D%22lingo-sub-468213%22%20slang%3D%22en-US%22%3EFormula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-468213%22%20slang%3D%22en-US%22%3EI%20need%20to%20find%20out%20how%20to%20use%20dashes%2Fhyphens%20in%20an%20IF%20formula%20without%20Excel%20trying%20to%20treat%20them%20like%20a%20minus%20sign.%20Ex%3A%20if%20cell%20A1%20says%20%22blue%22%2C%20then%20I%20want%20cell%20A2%20to%20say%20%22799-69999-1%22%20(exactly%20like%20this%20with%20the%20hyphens).%20However%2C%20cell%20A2%20is%20showing%20-59301.%20How%20do%20I%20make%20the%20end%20result%20in%20cell%20A2%20say%20%22799-69999-1%22%3F%20I%20also%20want%20to%20find%20a%20formula%20that%20will%20allow%20me%20to%20input%20multiple%20criteria.%20Ex%3A%20if%20cell%20A1%20says%20blue%2C%20then%20cell%20A2%20should%20be%20799-99999-1.%20If%20cell%20A1%20says%20red%2C%20then%20cell%20A2%20should%20be%20788-88888-1%2C%20etc.%20it%20would%20be%20up%20to%2010%20different%20criteria.%20Any%20help%20would%20be%20appreciated!%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-468213%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-468472%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-468472%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F322932%22%20target%3D%22_blank%22%3E%40lfreeman25%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBecause%20you%20can%20only%20use%20a%20maximum%20of%207%20layers%26nbsp%3B%20in%20a%20nested%20IF%20statement%2C%20below%20is%20a%20tip%20from%20John%20Walkenbach%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3EHow%20to%20use%20more%20than%207%20Nested%20IF%20statements%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3ESource%3A%20John%20Walkenbach%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3EUsing%20the%20CONCATENATE%20function%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EYet%20another%20option%20was%20suggested%20to%20me%20by%20B.%20Ganesh%3A%20Use%20the%20CONCATENATE%20function.%20In%20this%20case%2C%20each%20argument%20for%20CONCATENATE%20consists%20of%20an%20IF%20function.%20Here's%20an%20example%3A%3C%2FP%3E%3CP%3E%3DCONCATENATE(IF(A1%3D%22A%22%2C1%2C%22%22)%2CIF(A1%3D%22B%22%2C2%2C%22%22)%2CIF(A1%3D%22C%22%2C3%2C%22%22)%2C%3C%2FP%3E%3CP%3EIF(A1%3D%22D%22%2C4%2C%22%22)%2CIF(A1%3D%22E%22%2C5%2C%22%22)%2CIF(A1%3D%22F%22%2C6%2C%22%22)%2CIF(A1%3D%22G%22%2C7%2C%22%22)%2C%3C%2FP%3E%3CP%3EIF(A1%3D%22H%22%2C8%2C%22%22)%2CIF(A1%3D%22I%22%2C9%2C%22%22)%2CIF(A1%3D%22J%22%2C10%2C%22%22))%3C%2FP%3E%3CP%3EThe%20CONCATENATE%20function%20can%20handle%20as%20many%20as%2030%20arguments%20--%20which%20equates%20to%20testing%2030%20different%20conditions.%3C%2FP%3E%3CP%3EAnd%2C%20as%20Alan%20Williams%20pointed%20out%2C%20you%20can%20avoid%20using%20the%20CONCATENATE%20function%20and%20use%20the%20concatenation%20operator%20(%26amp%3B)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%20%3DIF(A1%3D%22A%22%2C1%2C%22%22)%26amp%3BIF(A1%3D%22B%22%2C2%2C%22%22)%26amp%3BIF(A1%3D%22C%22%2C3%2C%22%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26amp%3BIF(A1%3D%22D%22%2C4%2C%22%22)%26amp%3BIF(A1%3D%22E%22%2C5%2C%22%22)%26amp%3BIF(A1%3D%22F%22%2C6%2C%22%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%20%26amp%3BIF(A1%3D%22G%22%2C7%2C%22%22)%26amp%3BIF(A1%3D%22H%22%2C8%2C%22%22)%26amp%3BIF(A1%3D%22I%22%2C9%2C%22%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%20%26amp%3BIF(A1%3D%22J%22%2C10%2C%22%22)%3C%2FP%3E%3CP%3EThis%20method%20is%20not%20limited%20to%2030%20comparisons.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-468651%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-468651%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F322960%22%20target%3D%22_blank%22%3E%40Dutchman54%3C%2FA%3E%20%2C%20limit%20of%207%20layers%20is%20for%20Excel%202003%20and%20below%2C%20starting%20from%202007%20the%20limit%20is%2064.%20Modern%20IFS%20allows%20up%20to%20127%20condition.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHowever%2C%20in%20this%20case%20better%20to%20have%20helper%20table%20which%20maps%20one%20on%20another%20and%20use%20VLOOKUP%2C%20LOOKUP%20or%20INDEX%2FMATCH.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20it'll%20be%20no%20side%20effect%20when%3C%2FP%3E%0A%3CPRE%3E%3DIF(1%2C788-88888-1%2C)%3C%2FPRE%3E%0A%3CP%3Ewhere%20IF%20interprets%26nbsp%3B%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3E788-88888-1%3C%2FFONT%3E%20as%20%3D%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3E788-88888-1%3C%2FFONT%3E%20and%20returns%20-88101.%3C%2FP%3E%0A%3CP%3EIf%20to%20hardcode%20when%3C%2FP%3E%0A%3CPRE%3E%3DIF(1%2C%22788-88888-1%22%2C)%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
lfreeman25
Occasional Visitor
I need to find out how to use dashes/hyphens in an IF formula without Excel trying to treat them like a minus sign. Ex: if cell A1 says "blue", then I want cell A2 to say "799-69999-1" (exactly like this with the hyphens). However, cell A2 is showing -59301. How do I make the end result in cell A2 say "799-69999-1"? I also want to find a formula that will allow me to input multiple criteria. Ex: if cell A1 says blue, then cell A2 should be 799-99999-1. If cell A1 says red, then cell A2 should be 788-88888-1, etc. it would be up to 10 different criteria. Any help would be appreciated!
2 Replies

@lfreeman25 

 

Because you can only use a maximum of 7 layers  in a nested IF statement, below is a tip from John Walkenbach:

How to use more than 7 Nested IF statements:

Source: John Walkenbach

Using the CONCATENATE function

Yet another option was suggested to me by B. Ganesh: Use the CONCATENATE function. In this case, each argument for CONCATENATE consists of an IF function. Here's an example:

=CONCATENATE(IF(A1="A",1,""),IF(A1="B",2,""),IF(A1="C",3,""),

IF(A1="D",4,""),IF(A1="E",5,""),IF(A1="F",6,""),IF(A1="G",7,""),

IF(A1="H",8,""),IF(A1="I",9,""),IF(A1="J",10,""))

The CONCATENATE function can handle as many as 30 arguments -- which equates to testing 30 different conditions.

And, as Alan Williams pointed out, you can avoid using the CONCATENATE function and use the concatenation operator (&):

   =IF(A1="A",1,"")&IF(A1="B",2,"")&IF(A1="C",3,"")

    &IF(A1="D",4,"")&IF(A1="E",5,"")&IF(A1="F",6,"")

   &IF(A1="G",7,"")&IF(A1="H",8,"")&IF(A1="I",9,"")

   &IF(A1="J",10,"")

This method is not limited to 30 comparisons.

 

@Dutchman54 , limit of 7 layers is for Excel 2003 and below, starting from 2007 the limit is 64. Modern IFS allows up to 127 condition.

 

However, in this case better to have helper table which maps one on another and use VLOOKUP, LOOKUP or INDEX/MATCH.

 

When it'll be no side effect when

=IF(1,788-88888-1,)

where IF interprets 788-88888-1 as =788-88888-1 and returns -88101.

If to hardcode when

=IF(1,"788-88888-1",)