# Better way required to write 1 formula

#### hsandeep

##### Well-known Member
Any better 'way' to write the below formula:

=IF(AGG2=100,"i",IF(AGG2=200,"j",IF(AGC2=100,"p",IF(AGC2=-100,"q",IFERROR(CHOOSE(B2,"J","K","L","M"),0)))))

### Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I'm just giving you choices. If you want to create a user defined function instead, it's easier to read and easier to make changes.

Code:
``````Function GetChoice(R1 As Range, R2 As Range, R3 As Range) As Variant

If R1.Value = 100 Then
GetChoice = "i"
ElseIf R1.Value = 200 Then
GetChoice = "j"
ElseIf R2.Value = 100 Then
GetChoice = "p"
ElseIf R2.Value = -100 Then
GetChoice = "q"
ElseIf R3.Value = 1 Then
GetChoice = "j"
ElseIf R3.Value = 2 Then
GetChoice = "k"
ElseIf R3.Value = 3 Then
GetChoice = "l"
ElseIf R3.Value = 4 Then
GetChoice = "m"
Else
GetChoice = 0
End If

End Function``````

The cell formula would look something like this: =GetChoice(AGG2,AGC2,B2)

Add this line to the code if you want it to always refresh with cell changes: Application.Volatile

Add this line to the code if you want it to always refresh with cell changes: Application.Volatile

I want to use 'another' formula for the 'first 2' IFs (in the formula).

Replies
3
Views
108
Replies
21
Views
563
Replies
5
Views
358
Replies
1
Views
116
Replies
3
Views
170

1,203,538
Messages
6,055,992
Members
444,839
Latest member
laurajames

### 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.

### Which adblocker are you using?

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

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