Shorten these Or conditions

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi All,

How can I shorten these 2 formulas

VBA Code:
=IF(OR([@[Team Manager]]="Matt Gritton Team Blue2000",[@[Team Manager]]="Matt Gritton Team Green2000",[@[Team Manager]]="Academy2000"),"CS_ACADEMY",IF(OR([@[Team Manager]]="Matt Gritton Team Blue2001",[@[Team Manager]]="Matt Gritton Team Green2001",[@[Team Manager]]="Academy2001"),"CS_ACADEMY",IF(OR([@[Team Manager]]="Matt Gritton Team Blue2003",[@[Team Manager]]="Matt Gritton Team Green2003",[@[Team Manager]]="Academy2003"),"CS_ACADEMY",IF(OR([@[Team Manager]]="Matt Gritton Team Blue4000",[@[Team Manager]]="Matt Gritton Team Green4000",[@[Team Manager]]="Academy4000"),"COSC_ACADEMY",[@[Team Manager]]))))


VBA Code:
=IFERROR(SUMPRODUCT(--(tbl_Agent_Results[AHT]),--(tbl_Agent_Results[contactsHandled]),--(tbl_Agent_Results[Date_]=I$5),(--(tbl_Agent_Results[Team Manager]="MATT GRITTON TEAM GREEN4000")+--(tbl_Agent_Results[Team Manager]="MATT GRITTON TEAM BLUE4000")+--(tbl_Agent_Results[Team Manager]="Academy4000")))/SUMPRODUCT(--(tbl_Agent_Results[contactsHandled]),--(tbl_Agent_Results[Date_]=I$5),(--(tbl_Agent_Results[Team Manager]="MATT GRITTON TEAM GREEN4000")+--(tbl_Agent_Results[Team Manager]="MATT GRITTON TEAM BLUE4000")+--(tbl_Agent_Results[Team Manager]="Academy4000"))),"")

I have the same multiple or conditions and was hoping I can make this slicker and more easier to condense it down as the condition could grow

Many Thanks
 
For the first one, I'd recommend using a lookup table instead of listing all the values in the formula. Here's a sample of what that would look like.

Book1 (version 1).xlsb
ABCDEFGHIJK
1abcdTeam ManagerTeam ManagerCode
2123Matt Gritton Team Blue2000Matt Gritton Team Blue2000Matt Gritton Team Blue2000CS_ACADEMY
3Matt Gritton Team Green2000CS_ACADEMY
4Academy2000CS_ACADEMY
5Matt Gritton Team Blue2001Academy2001
6Matt Gritton Team Green2001Academy2001
7
Sheet4
Cell Formulas
RangeFormula
D2D2=IFERROR(VLOOKUP([@[Team Manager]],$J$2:$K$6,0),[@[Team Manager]])


For the second formula, again I'd use a lookup table, as Mike suggested. Instead of using

=SUMPRODUCT( . . . (--(tbl_Agent_Results[Team Manager]="MATT GRITTON TEAM GREEN4000")+--(tbl_Agent_Results[Team Manager]="MATT GRITTON TEAM BLUE4000")+--(tbl_Agent_Results[Team Manager]="Academy4000")) . . .)

try:

=SUMPRODUCT(. . .--ISNUMBER(MATCH((tbl_Agent_Results[Team Manager],$J$2:$J$4,0)) . . .)

where J2:J4 has the list of valid values.
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

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