Try to use CHOOSE instead of IF
Try to use CHOOSE instead of IF
2
IJR (Structural)
(OP)
Nothing drives one crazy than a series of IF inside an IF. But we usually start with Fortran and Basic programming before going into spreadsheet programming. By default, we love the IF( )
I find the CHOOSE function in Excel a very useful tool. Those who havent tried, try it and those who have used it creatively lets learn more from you
Regards
IJR
I find the CHOOSE function in Excel a very useful tool. Those who havent tried, try it and those who have used it creatively lets learn more from you
Regards
IJR





RE: Try to use CHOOSE instead of IF
RE: Try to use CHOOSE instead of IF
insead of:
=IF(A1=1,"one",IF(A1=2,"two",IF(A1=3,"three",">three")))
use the "choose" function:
=Choose(A1,"one","two","three")
The problem with the choose statement is that (as far as I know), if you enter a number > 3 into cell A1, you get a #VALUE error in the choose cell. You can of course remidy this with a conditional statement (assuming no zero or negative numbers are to be entered):
=IF(A1<=3,Choose(A1,"one","two","three"),">three")
Hope this helps.
RE: Try to use CHOOSE instead of IF
I have developed this function in VBA (like select case in VBA)
Public Function FindCase(TxtStr, TxtDefaultValue, ParamArray VarAnsArray())
Dim i As Integer
FindCase = TxtDefaultValue
For i = 0 To UBound(VarAnsArray) - 1 Step 2
If TxtStr = VarAnsArray(i) Then
FindCase = VarAnsArray(i + 1)
Exit Function
End If
Next
End Function
we can use like this
=FINDCASE(A1,1,"A",1,"A2L",2,"A2S",1,"A4S",2)
IF cell A1 CONTAIN "A" RESULT WILL BE 1 (3rd & 4th arguments)
IF A1 CONTAIN "A2L" RESULT WILL BE 2(5th & 6th)
IF A1 CONTAIN "A2S" RESULT WILL BE 1(7th & 8th)
IF A1 CONTAIN "A4S" RESULT WILL BE 2(9th & 10th)
ELSE RESULT WILL BE 1 (second argument)
I tried to developed similer to select case statments in VBA
I have tried with string argument & it work OK.
Nitin Patel
India
RE: Try to use CHOOSE instead of IF
I've been looking for this type of function for a LONG time.
Verrry cool.