Question

I am currently doing a "if then" loop in excel with following logic.

Value to Check

1. S9(7) C3
2. S9(11)V9(2) C3
3. X(3)

Logic I have used

=IF(ISNUMBER(SEARCH("S9",D1,1)),CONCATENATE("s370fpd",5,".","0"),CONCATENATE("$ebcdic",5,"."))

Now problem here is that S9 maybe of two types. In the first one i.e. S9(7) C3 it works fine but for second one i.e. S9(11)V9(2) C3 I have to CONCATENATE "s370fpd" with value inside bracket of V9 i.e. 2 in this case. So it will become "s370fpd5.2".

Since the value inside bracket is dynamic hence the logic has to search inside it. I am not sure how it will check and then append it.

Was it helpful?

Solution

I'm not sure what you're trying to do exactly, but keeping as much as what you have right now as possible, I would use this:

=IF(ISNUMBER(SEARCH("S9",D1,1)),CONCATENATE("s370fpd",5,".",IFERROR(MID(D1,SEARCH("V9",D1)+3,SEARCH(")",D1,SEARCH("V9",D1))-SEARCH("V9",D1)-3),"0")),CONCATENATE("$ebcdic",5,"."))

I substituted "0" with

IFERROR(MID(D1,SEARCH("V9",D1)+3,SEARCH(")",D1,SEARCH("V9",D1))-SEARCH("V9",D1)-3),"0")

which is what gets what's between brackets after V9.

It also appears to me that you can turn CONCATENATE("$ebcdic",5,".") into "$ebcdic5." directly and CONCATENATE("s370fpd",5,"." into CONCATENATE("s370fpd5.", and/or use & to make things a little shorter, but that's only subject to what you've put in your question:

=IF(ISNUMBER(SEARCH("S9",D1,1)),"s370fpd5."&IFERROR(MID(D1,SEARCH("V9",D1)+3,SEARCH(")",D1,SEARCH("V9",D1))-SEARCH("V9",D1)-3),"0"),"$ebcdic5.")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top