Choose from multiple formulas

2077delta

Active Member
Joined
Feb 17, 2002
Messages
252
Office Version
  1. 365
Platform
  1. Windows
Is there a simpler way than using a nested if statement to apply a formula based on the result of a cell? For example, in Cell A3 I have a formula that evaluates the value in Cell A1 and applies a formula that extracts text in Cell A2 depending on the value in Cell A1. Something like =function name(value of A1, formula1, formula2, formula3, formula4, formula5). Similar to the choose function only using formulas based on the index value instead of values. Is building a VBA function my only option?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Depending on your situation, either IFS or SWITCH could work.

Examples:

Excel Formula:
=IFS(A1=1,MID(A2,2,3),A1=2,LEFT(A2,4),A1=3,RIGHT(A2,4),TRUE,"invalid value")

Excel Formula:
=SWITCH(A1,1,LEFT(A2,1),2,MID(A2,2,2),3,RIGHT(A2),"oops")
 
Upvote 0
Depending on your situation, either IFS or SWITCH could work.

Examples:

Excel Formula:
=IFS(A1=1,MID(A2,2,3),A1=2,LEFT(A2,4),A1=3,RIGHT(A2,4),TRUE,"invalid value")

Excel Formula:
=SWITCH(A1,1,LEFT(A2,1),2,MID(A2,2,2),3,RIGHT(A2),"oops")
Thanks Eric, IFS was the answer I was looking for. Here's my formula
=LET(y,XLOOKUP(B4,src_names,src_index),z,V4,IFS(y=1,TEXTBEFORE(TEXTAFTER(z,"`",1),"",1),y=2,TEXTBEFORE(TEXTAFTER(z,"`",1),"",1),y=3,TEXTBEFORE(TEXTAFTER(z,"",1),":",1),y=4,TEXTBEFORE(TEXTAFTER(z,"`",1),"",1),y=5,TEXTBEFORE(TEXTAFTER(z,"`",1),"",1),y=6,TEXTBEFORE(TEXTAFTER(z,"`",1),"",1)))
When our accounting system exports it concatenates a bunch of fields together and inserts these awkward symbols so I have to split up a long text string so we can work with the data.
 
Upvote 0

Forum statistics

Threads
1,215,212
Messages
6,123,656
Members
449,114
Latest member
aides

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