Conditional Excel formula

nostradamus

Board Regular
Joined
Aug 9, 2010
Messages
143
Office Version
  1. 365
Platform
  1. Windows
Hi all,
I have a complicated Conditional Excel formula that needs improvement on:
Sheet1 =has the MATCH INDEX information
Sheet2 =is where I need the formula to be prepared/edited.

Currently,in Shee2:E2, I have a formula that matches info from Sheet2:C2 to Sheet1:C and pulls the appropriate info from Sheet1:D. So, the current formula in Sheet2:E2works great
{=IF(ISERROR(INDEX(Sheet1!$A:$D,MATCH($C2,Sheet1!$C:$C,FALSE),4)),"",INDEX(Sheet1!$A:$D,MATCH
($C2,Sheet1!$C:$C,FALSE),4))}

However,I have an addition in Sheet2 where info in Col.D needs to be used in determining what goes in Col.E (for instance, if nothing is in Sheet2:D2, then just put whatever info goes there (Col.E2). But if Sheet2:D2 has A or L, then that information needs to be taken into consideration from Sheet1:Col.D. Now,Col.D2-D6 currently has no A or L info; but in Col.D7, if L, then it's P, and if A, then it's CG.

Hopefully,you are able to understand what I am trying to get from this formula. Sheet2:Col.F shows the appropriate results I want.
Please see Sheet1 and Sheet2 info below: Thanks

Sheet1
ABCD
1OrderFamilyGenusFunctionalGroup
2LepidopteraPyralidaePetrophilaSCR
3ColeopteraElmidaeAncyronyxSCR/CG
4ColeopteraGyrinidaeDineutusP
5ColeopteraHydrophilidaeHelocharesCG
6ColeopteraScirtidaeScirtidaeSCR/CG/SHR
7ColeopteraHydrophilidaeHydrophilidaeL=P;A=CG
8ColeopteraHydrophilidaeBerosusL=P;A=CG
9ColeopteraHydrophilidaeHydrocanthusL=P/CG;A=P
10ColeopteraHaliplidaeHaliplidaeSHR/P
11DipteraChironomidaeEndochironomusSHR/CG/FC
12DipteraChironomidaeGlyptotendipesSHR/FC/CG

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4

Sheet2
ABCDEF
1OrderFamilyGenusStageTrophic GuildResultWanted
2LepidopteraPyralidaePetrophilaSCRSCR
3ColeopteraElmidaeAncyronyxASCR/CGSCR/CG
4ColeopteraGyrinidaeDineutusLPP
5ColeopteraHydrophilidaeHelocharesLCGCG
6ColeopteraScirtidaeCyphonLSCR/CG/SHRSCR/CG/SHR
7ColeopteraHydrophilidaeHydrophilidaeLL=P;A=CGP
8ColeopteraHydrophilidaeHydrophilidaeAL=P;A=CGCG
9ColeopteraHydrophilidaeBerosusAL=P;A=CGCG
10ColeopteraHydrophilidaeBerosusLL=P;A=CGP
11ColeopteraHydrophilidaeHydrocanthusLL=P/CG;A=PP/CG
12ColeopteraHydrophilidaeHydrocanthusAL=P/CG;A=PP
13ColeopteraHaliplidaeHaliplidaeASHR/PSHR/P
14DipteraChironomidaeEndochironomusSHR/CG/FCSHR/CG/FC
15DipteraChironomidaeGlyptotendipesSHR/FC/CGSHR/FC/CG
16OdonataCoenagrionidaeArgiaPPP

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I found it a bit difficult to get everything you wanted in one formula. Instead I left your E2 formula alone (mostly - I rewrote it using IFERROR which has been available since Excel 2007), and added a new column to extract the part of the response you wanted. Put the formula in F2 and copy down. It also uses IFERROR, so if you have an older version of Excel we'll have to fall back and retry.

ABCDEFG
1OrderFamilyGenusStageTrophic GuildResultWantedResultWanted
2LepidopteraPyralidaePetrophilaSCRSCRSCR
3ColeopteraElmidaeAncyronyxASCR/CGSCR/CGSCR/CG
4ColeopteraGyrinidaeDineutusLPPP
5ColeopteraHydrophilidaeHelocharesLCGCGCG
6ColeopteraScirtidaeCyphonLSCR/CG/SHR
7ColeopteraHydrophilidaeHydrophilidaeLL=P;A=CGPP
8ColeopteraHydrophilidaeHydrophilidaeAL=P;A=CGCGCG
9ColeopteraHydrophilidaeBerosusAL=P;A=CGCGCG
10ColeopteraHydrophilidaeBerosusLL=P;A=CGPP
11ColeopteraHydrophilidaeHydrocanthusLL=P/CG;A=PP/CGP/CG
12ColeopteraHydrophilidaeHydrocanthusAL=P/CG;A=PPP
13ColeopteraHaliplidaeHaliplidaeASHR/PSHR/PSHR/P
14DipteraChironomidaeEndochironomusSHR/CG/FCSHR/CG/FCSHR/CG/FC
15DipteraChironomidaeGlyptotendipesSHR/FC/CGSHR/FC/CGSHR/FC/CG
16OdonataCoenagrionidaeArgiaPP

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet2

Worksheet Formulas
CellFormula
E2=IFERROR(INDEX(Sheet1!$A:$D,MATCH($C2,Sheet1!$C:$C,FALSE),4),"")
F2=IF(D2="",E2,IFERROR(MID(E2,SEARCH(D2&"=",E2)+2,FIND(";",E2&";",SEARCH(D2&"=",E2))-SEARCH(D2&"=",E2)-2),E2))

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

I didn't get a match on E6, and the G16 Result Wanted value seems to be a typo.

Now if you want you can hide column E.

Hope this helps.
 
Upvote 0
Eric, your formula works great, thanks a bunch. One more question tho - if there is no match, then I want the cell to remain blank, currently with your formula a no match returns a "0". Could you pl add on to your formula the "" part? :eek:.
 
Upvote 0
Just add &"" to the end, like this:

=IFERROR(INDEX(Sheet1!$A:$D,MATCH($C2,Sheet1!$C:$C,FALSE),4),"")&""

;)
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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