IF(OR....Alternatives

mrsushi

Board Regular
Joined
Nov 18, 2006
Messages
180
Office Version
  1. 2010
Good morning,

I have the following formula which appears to only limit the number of items within the statement. I cant seem to fit anymore IF statements within this formula. Is there an alternative where i can add more?

=IF(OR(N2="Rimes"),CONCATENATE(C2,D2,".CSV"),IF((N2="FTSE"),CONCATENATE(C2,E2,".CSV"),IF((N2="Barclays"),CONCATENATE(C2,F2,".CSV"),IF((N2="Bloomberg"),CONCATENATE(C2,G2,".CSV"),IF((N2="Iboxx"),CONCATENATE(C2,H2,".CSV"),IF((N2="ICEBoAML"),CONCATENATE(C2,I2,".CSV"),IF((N2="Markit"),CONCATENATE(C2,J2,".CSV"),"Check File Name")))))))

Many thanks
M
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
One way would be to build your own User Defined Function (UDF) in VBA, where you can add as many options as you like. The code would look something like this:
VBA Code:
Function BuildFileName(str As String) As String

    Dim addr As String
    Dim fName As String
    
    Select Case str
        Case "Rimes"
            addr = "D2"
        Case "FTSE"
            addr = "E2"
        Case "Barclays"
            addr = "F2"
        Case "Bloomberg"
            addr = "G2"
        Case "Iboxx"
            addr = "H2"
        Case "ICEBoAML"
            addr = "I2"
        Case "Markit"
            addr = "J2"
        Case Else
            addr = "Check File Name"
    End Select
    
    If addr = "Check File Name" Then
        BuildFileName = addr
    Else
        BuildFileName = Range("C2") & addr & ".CSV"
    End If
    
End Function

Then you would just use it on your sheet like any other Excel function, i.e.
Excel Formula:
=BuildFileName(N2)
 
Upvote 0
There is a limit of about 64 nested IF arguments allowed and you are far from that, how many companies are you thinking of adding?
If there are only a few more then just add extra like line in Bold below and change concatenate cell as required, also remember to add closing bracket for every argument you add
=IF(OR(N2="Rimes"),CONCATENATE(C2,D2,".CSV"),IF((N2="FTSE"),CONCATENATE(C2,E2,".CSV"),IF((N2="Barclays"),CONCATENATE(C2,F2,".CSV"),IF((N2="Bloomberg"),CONCATENATE(C2,G2,".CSV"),IF((N2="Iboxx"),CONCATENATE(C2,H2,".CSV"),IF((N2="ICEBoAML"),CONCATENATE(C2,I2,".CSV"),IF((N2="Markit"),CONCATENATE(C2,J2,".CSV"),IF((N2="XXXXX"),CONCATENATE(C2,K2,".CSV"),"Check File Name"))))))))
 
Upvote 0
There is a limit of about 64 nested IF arguments allowed and you are far from that, how many companies are you thinking of adding?
If there are only a few more then just add extra like line in Bold below and change concatenate cell as required, also remember to add closing bracket for every argument you add
=IF(OR(N2="Rimes"),CONCATENATE(C2,D2,".CSV"),IF((N2="FTSE"),CONCATENATE(C2,E2,".CSV"),IF((N2="Barclays"),CONCATENATE(C2,F2,".CSV"),IF((N2="Bloomberg"),CONCATENATE(C2,G2,".CSV"),IF((N2="Iboxx"),CONCATENATE(C2,H2,".CSV"),IF((N2="ICEBoAML"),CONCATENATE(C2,I2,".CSV"),IF((N2="Markit"),CONCATENATE(C2,J2,".CSV"),IF((N2="XXXXX"),CONCATENATE(C2,K2,".CSV"),"Check File Name"))))))))
If they are using Excel 2010 (which is what their profile says), it may be less than that.
Older versions of Excel only allowed nesting up to 7 levels.
 
Upvote 0
True Joe all depends on Excel version thought it was 7 up to version 2007 and 64 after that but may be wrong
 
Upvote 0
Another option is
Excel Formula:
=IFNA(CONCATENATE(C2,INDEX(D2:J2,MATCH(N2,{"Rimes","FTSE""Barclays","Bloomberg","Iboxx","ICEBoAML","Markit"},0)),".CSV"),"Check file name")
 
Upvote 0

Forum statistics

Threads
1,215,100
Messages
6,123,086
Members
449,095
Latest member
gwguy

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