Home

help with IF statement...

%3CLINGO-SUB%20id%3D%22lingo-sub-683975%22%20slang%3D%22en-US%22%3Ehelp%20with%20IF%20statement...%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-683975%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20laboratory%20instrument%20which%20spits%20out%20mostly%20numbers%2C%20but%20occasionally%20a%20phrase%2C%20such%20as%20%22N%2FA%22%20or%20%22No%20Peak%22%20or%20%22%26lt%3B0%22.%20However%2C%20I%20needed%20a%20column%20in%20excel%20that%20only%20contained%20numbers...so%20I%20made%20this%20formula%20to%20convert%20any%20of%20these%20statement%20to%20%220%22%20in%20the%20neighboring%20column%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3DIF(INDIRECT(background!%24B%243%20%26amp%3B%20%222%3A%22%26amp%3Bbackground!%24B%243%20%26amp%3B%20%22245%22)%3D%22No%20Peak%22%2C0%2CIF(INDIRECT(background!%24B%243%20%26amp%3B%20%222%3A%22%20%26amp%3B%20background!%24B%243%20%26amp%3B%20%22245%22)%3D%22N%2FA%22%2C0%2CIF(INDIRECT(background!%24B%243%20%26amp%3B%20%222%3A%22%26amp%3Bbackground!%24B%243%20%26amp%3B%20%22245%22)%3D%22%26lt%3B%200%22%2C0%2CINDIRECT(background!%24B%243%20%26amp%3B%20%222%3A%22%26amp%3Bbackground!%24B%243%20%26amp%3B%20%22245%22))))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E(the%20INDIRECT%20portion%20cobbles%20together%20a%20column%20letter%20and%20a%20number%20from%20a%20phrase%20it%20searches%20for%20on%20another%20tab.%20I%20don't%20think%20that's%20relevant%20here%2C...just%20the%20IF%20statement).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20it%20works%20fine%2C%20But%2C%20the%20instrument%20also%20spits%20out%20the%20phrase%20%22%23DIV%2F0!%22%20and%20excel%20doesn't%20know%20what%20to%20do%20with%20it....it%20just%20provides%20the%20phrase%20again%20in%20the%20formula%20column.%20Any%20ideas%20how%20I%20can%20get%20this%20phrase%20to%20convert%20to%20%220%22%20properly%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-683975%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-684003%22%20slang%3D%22en-US%22%3ERe%3A%20help%20with%20IF%20statement...%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-684003%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F301568%22%20target%3D%22_blank%22%3E%40gms4b%3C%2FA%3E%26nbsp%3B%2C%20you%20may%20wrap%20your%20formula%20with%20IFERROR%3C%2FP%3E%0A%3CPRE%3E%3DIFERROR(%26lt%3Bformula%26gt%3B%2C0)%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-684008%22%20slang%3D%22en-US%22%3ERe%3A%20help%20with%20IF%20statement...%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-684008%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F301568%22%20target%3D%22_blank%22%3E%40gms4b%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPerhaps%20entire%20formula%3C%2FP%3E%0A%3CPRE%3E%3DIFERROR(%20IF(SUMPRODUCT(--(INDIRECT(background!%24B%243%20%26amp%3B%20%222%3A%22%26amp%3Bbackground!%24B%243%20%26amp%3B%20%22245%22)%3D%7B%22No%20Peak%22%2C%22N%2FA%22%2C%22%26lt%3B%200%22%7D))%2C0%2CINDIRECT(background!%24B%243%20%26amp%3B%20%222%3A%22%26amp%3Bbackground!%24B%243%20%26amp%3B%20%22245%22))%2C0)%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-684071%22%20slang%3D%22en-US%22%3ERe%3A%20help%20with%20IF%20statement...%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-684071%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAhHa!%20So%20I%20simply%20did%20this%20and%20it%20worked%20to%20take%20out%20the%20%23DIV%2F0!%20statement%20and%20turn%20it%20to%20a%200.%20The%20remainder%20of%20the%20formula%20still%20converts%20the%20other%20statements%20to%200.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20not%20sure%20what's%20going%20on%20with%20the%20other%20formula%20but%20its%20not%20really%20working%20right.%20I%20think%20it%20was%20giving%200's%20for%20everything...including%20normal%20numbers.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20your%20help!!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGreg%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-684868%22%20slang%3D%22en-US%22%3ERe%3A%20help%20with%20IF%20statement...%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-684868%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F301568%22%20target%3D%22_blank%22%3E%40gms4b%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHi%20Greg%2C%3C%2FP%3E%0A%3CP%3EPlease%20check%20attached%20how%20it%20works%20in%20this%20sample%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20497px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F117828iC10C3A97BBFEE8E9%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-684908%22%20slang%3D%22en-US%22%3ERe%3A%20help%20with%20IF%20statement...%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-684908%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20Sergei...I%20will%20keep%20playing%20with%20it.%20If%20I%20use%20your%20formula%20and%20put%20in%20the%20direct%20cell%20then%20things%20do%20work%20correctly.%20When%20I%20substitute%20in%20the%20INDIRECT%20portion%20instead%20of%20the%20direct%20cell%20name%20then%20it%20breaks%20and%20just%20gives%20me%200.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'll%20play%20with%20it%20again%20tomorrow....time%20to%20pick%20kids%20up%20from%20school.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EGreg%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-685027%22%20slang%3D%22en-US%22%3ERe%3A%20help%20with%20IF%20statement...%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-685027%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F301568%22%20target%3D%22_blank%22%3E%40gms4b%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGreg%2C%20I%20missed%20what%20INDIRECT()%20returns%20range%2C%20not%20the%20cell.%20If%20so%20simply%20wrap%20the%20formula%20by%20IFERROR%20like%3C%2FP%3E%0A%3CPRE%3E%3DIFERROR(IF(A1%3AA12%3D%22No%20Peak%22%2C0%2CIF(A1%3AA12%3D%22N%2FA%22%2C0%2CIF(A1%3AA12%3D%22%26lt%3B%200%22%2C0%2CA1%3AA12)))%2C0)%3C%2FPRE%3E%0A%3CP%3Eto%20optimize%20it%20it%20desirably%20to%20know%20more%20details%20of%20how%20your%20data%20is%20structured.%20It%20looks%20like%20you%20return%20the%20value%20from%20background%20sheet%20into%20the%20current%20row%20by%20row%2C%20from%20row%202%20to%20row%203%2C%20from%203%20to%203%2C%20etc%20and%20column%20by%20column.%20But%20I'm%20not%20sure.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-687405%22%20slang%3D%22en-US%22%3ERe%3A%20help%20with%20IF%20statement...%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-687405%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYeah%2C%20I%20think%20I'll%20just%20keep%20with%20wrapping%20my%20old%20formula%20in%20IFERROR%20like%20you%20suggested.%20That%20works%20well!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20think%20you're%20correct%20in%20your%20assessment.%20Column%20R%20in%20my%20spreadsheet%20contains%20all%20the%20data%20including%20several%20text%20terms......but%20I%20need%20the%20column%20to%20only%20contain%20numbers%20-%20and%20that%20is%20accomplished%20in%20column%20AC.%20The%20original%20formula%20converted%20most%20of%20the%20terms%20to%200%20(like%20N%2FA)%20but%20not%20%23DIV%2F0!.%20Wrapping%20the%20formula%20in%20IFERROR%20took%20care%20of%20that%20as%20you%20can%20see%20(for%20R2---%26gt%3BAC2).%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%2C%20there's%20an%20INDEX%20function%20elsewhere%20that%20looks%20for%20a%20certain%20word%20(%22calculated%20concentration%20(ng%2Fmg)%22)%20from%20a%20column%20header%20and%20returns%20the%20column%20number%20that%20it%20is%20in%20and%20then%20converts%20it%20into%20the%20column%20letter%20(in%20the%20%22background%22%20sheet).%20That%20letter%20(in%20this%20case%20it's%20R)%20is%20then%20referenced%20in%20the%20formula's%20INDIRECT%20statement%20to%20point%20to%20a%20range%20of%20cells......so%2C%20R2%3AR245%20for%20instance.%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20308px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F117897i28B2AC089C3B4747%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EUsing%20the%20entire%20range%20in%20the%20formula%20still%20returns%20the%20result%20from%20the%20corresponding%20row%20when%20you%26nbsp%3Bcut%2Fpaste%20the%20formula%20from%20row%202%20to%20245%20(i.e.%20the%20formula%20doesn't%20seem%20to%20need%20the%20exact%20cell%20number).%20But%2C%20maybe%20that's%20how%20its%20supposed%20to%20work.%20I'm%20not%20an%20Excel%20expert%2C%20in%20fact%2C%20I'm%20pretty%20sure%20that%20someone%20from%20this%20forum%20helped%20me%20with%20this%20formula!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20guess%20the%20problem%20is%20that%20I%20need%20to%20have%20the%20INDIRECT%20command%20in%20there%20because%20in%20my%20next%20data%20set%20the%20data%20could%20be%20in%20column%20S%20or%20U%20or%20somewhere%20else...it%20could%20change.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%2C%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EGreg%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-687751%22%20slang%3D%22en-US%22%3ERe%3A%20help%20with%20IF%20statement...%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-687751%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F301568%22%20target%3D%22_blank%22%3E%40gms4b%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGreg%2C%20it's%20not%20necessary%20to%20use%20INDIRECT%2C%20you%20already%20return%20needed%20column%20number%2C%20use%20it%20on%20INDEX%20for%20entire%20sheet%20like%3C%2FP%3E%0A%3CPRE%3E%3DIFERROR(%0A%20%20%20%20IF(%0A%20%20%20%20%20%20%20SUMPRODUCT(--(INDEX(background!A%3AZ%2CROW()%2CMATCH(Sheet1!B%241%2Cbackground!%241%3A%241%2C0))%3D%7B%22No%20Peak%22%2C%22N%2FA%22%2C%22%26lt%3B%200%22%7D))%2C%0A%20%20%20%20%20%20%200%2C%0A%20%20%20%20%20%20%20INDEX(background!A%3AZ%2CROW()%2CMATCH(Sheet1!B%241%2Cbackground!%241%3A%241%2C0))%0A%20%20%20%20)%2C0)%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
gms4b
Contributor

I have a laboratory instrument which spits out mostly numbers, but occasionally a phrase, such as "N/A" or "No Peak" or "<0". However, I needed a column in excel that only contained numbers...so I made this formula to convert any of these statement to "0" in the neighboring column:

 

=IF(INDIRECT(background!$B$3 & "2:"&background!$B$3 & "245")="No Peak",0,IF(INDIRECT(background!$B$3 & "2:" & background!$B$3 & "245")="N/A",0,IF(INDIRECT(background!$B$3 & "2:"&background!$B$3 & "245")="< 0",0,INDIRECT(background!$B$3 & "2:"&background!$B$3 & "245"))))

 

(the INDIRECT portion cobbles together a column letter and a number from a phrase it searches for on another tab. I don't think that's relevant here,...just the IF statement).

 

And it works fine, But, the instrument also spits out the phrase "#DIV/0!" and Excel doesn't know what to do with it....it just provides the phrase again in the formula column. Any ideas how I can get this phrase to convert to "0" properly?

8 Replies

@gms4b , you may wrap your formula with IFERROR

=IFERROR(<formula>,0)

 

@gms4b 

Perhaps entire formula

=IFERROR( IF(SUMPRODUCT(--(INDIRECT(background!$B$3 & "2:"&background!$B$3 & "245")={"No Peak","N/A","< 0"})),0,INDIRECT(background!$B$3 & "2:"&background!$B$3 & "245")),0)

@Sergei Baklan 

 

AhHa! So I simply did this and it worked to take out the #DIV/0! statement and turn it to a 0. The remainder of the formula still converts the other statements to 0. 

 

I'm not sure what's going on with the other formula but its not really working right. I think it was giving 0's for everything...including normal numbers. 

 

Thanks for your help!!

 

Greg

 

@gms4b 

 

Hi Greg,

Please check attached how it works in this sample

image.png

 

@Sergei Baklan 

 

Thanks Sergei...I will keep playing with it. If I use your formula and put in the direct cell then things do work correctly. When I substitute in the INDIRECT portion instead of the direct cell name then it breaks and just gives me 0. 

 

I'll play with it again tomorrow....time to pick kids up from school.

 

Thanks,


Greg

 

@gms4b 

 

Greg, I missed what INDIRECT() returns range, not the cell. If so simply wrap the formula by IFERROR like

=IFERROR(IF(A1:A12="No Peak",0,IF(A1:A12="N/A",0,IF(A1:A12="< 0",0,A1:A12))),0)

to optimize it it desirably to know more details of how your data is structured. It looks like you return the value from background sheet into the current row by row, from row 2 to row 3, from 3 to 3, etc and column by column. But I'm not sure.

@Sergei Baklan 

 

Yeah, I think I'll just keep with wrapping my old formula in IFERROR like you suggested. That works well!

 

I think you're correct in your assessment. Column R in my spreadsheet contains all the data including several text terms......but I need the column to only contain numbers - and that is accomplished in column AC. The original formula converted most of the terms to 0 (like N/A) but not #DIV/0!. Wrapping the formula in IFERROR took care of that as you can see (for R2--->AC2). 

 

So, there's an INDEX function elsewhere that looks for a certain word ("calculated concentration (ng/mg)") from a column header and returns the column number that it is in and then converts it into the column letter (in the "background" sheet). That letter (in this case it's R) is then referenced in the formula's INDIRECT statement to point to a range of cells......so, R2:R245 for instance. 

image.png

Using the entire range in the formula still returns the result from the corresponding row when you cut/paste the formula from row 2 to 245 (i.e. the formula doesn't seem to need the exact cell number). But, maybe that's how its supposed to work. I'm not an Excel expert, in fact, I'm pretty sure that someone from this forum helped me with this formula!

 

I guess the problem is that I need to have the INDIRECT command in there because in my next data set the data could be in column S or U or somewhere else...it could change. 

 

Cheers,


Greg

 

 

 

@gms4b 

Greg, it's not necessary to use INDIRECT, you already return needed column number, use it on INDEX for entire sheet like

=IFERROR(
    IF(
       SUMPRODUCT(--(INDEX(background!A:Z,ROW(),MATCH(Sheet1!B$1,background!$1:$1,0))={"No Peak","N/A","< 0"})),
       0,
       INDEX(background!A:Z,ROW(),MATCH(Sheet1!B$1,background!$1:$1,0))
    ),0)

 

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
46 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies