# If X is greater than Y in a cell

#### Mr2017

##### Well-known Member
Hi

I've got three formulae that work in isolation, but not together.

If the text "4 for 10" is in cell A1, I'd like one formula that returns the text "Multi deal where X<Y" if 4 is greater than 10, which it is. But returns "Multi deal where X>Y"if the text in cell A2 was 10 for 4.

The formulae which work in isolation are as follows:

This formula in cell B1 returns the word "for" if that text is in A1:

=IF(ISNUMBER(SEARCH("for",A1)),"For","")

This formula returns the first number on the left of A1 (if it has the word "for")

=RIGHT(TRIM(LEFT(A1,SEARCH("for",A1)-1)),2)

This formula returns the number on the right of the cell (if it has the word "for")

=TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",100)),100))

But when I combine them together, I get an error message.

Eg this should return "Multi deal where X <Y" but it doesn't (if this formula is in cell D1). Does anyone know the solution, please?

=IF(and((ISNUMBER(SEARCH("for",A1)),"For",RIGHT(TRIM(LEFT(A1,SEARCH("for",A1)-1)),2)>TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",100)),100))),"Multi Deal where X>Y",IF(and((ISNUMBER(SEARCH("for",A1)),"For",RIGHT(TRIM(LEFT(A1,SEARCH("for",A1)-1)),2)<TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",100)),100))),"Multi Deal where X<Y",""))))

#### Mr2017

##### Well-known Member
Yeah!!

Thanks!!

I think I may have added the the +0 one bracket too early, previously, but I tested out what you said above in a different place, and it worked!

Thanks again! That's a massive help!

### Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Replies
3
Views
193
Replies
12
Views
267
Replies
3
Views
86
Replies
7
Views
283
Replies
1
Views
200

1,141,121
Messages
5,704,427
Members
421,347
Latest member
vrajesh544

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