Problem with MID function

Tornado1981

Board Regular
Joined
Apr 1, 2010
Messages
248
Hi,


I'm trying to check if the first integer in A1 is greater than "3" then B1="OK" else B1="Not OK"


This is the function i'm using but B1 is always "OK"


Any help please ??


Code:
B1=IF(MID(A1,1,1)>3,"OK","Not OK")
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi,


I'm trying to check if the first integer in A1 is greater than "3" then B1="OK" else B1="Not OK"


This is the function i'm using but B1 is always "OK"
Code:
B1=IF(MID(A1,1,1)>3,"OK","Not OK")
The MID function returns text, not numbers, and text is alway greater than numbers, hence your results. The key is to involve the numerical text in a mathematical operation which forces Excel to convert the text number to a real number...

=IF(1*MID(A1,1,1)>3,"OK","Not OK")

The multiplication by one converts the digit to a number without changing its value. You could also add zero to the expression in place of the multiplication and that would work too (you could also prefix the MID function with two minus signs and that would also work).
 
Last edited:
Upvote 0
Another approach is to test against strings rather than numbers. That helps prevent error values being returned if the first character in A1 is non-numeric.

=IF(AND("3" < MID(A1,1,1), MID(A1,1,1)<="9"), "ok", "not")
 
Last edited:
Upvote 0
Hi,


I'm trying to check if the first integer in A1 is greater than "3" then B1="OK" else B1="Not OK"


This is the function i'm using but B1 is always "OK"


Any help please ??


Code:
B1=IF(MID(A1,1,1)>3,"OK","Not OK")
Here's another one.

=IF(--LEFT(A1)<4,"Not ","")&"OK"

Assumes the cell will only contain integers.
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,461
Members
449,085
Latest member
ExcelError

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