IF statement issue appears to be only reading 2 digits

%3CLINGO-SUB%20id%3D%22lingo-sub-2331694%22%20slang%3D%22en-US%22%3EIF%20statement%20issue%20appears%20to%20be%20only%20reading%202%20digits%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2331694%22%20slang%3D%22en-US%22%3E%3CP%3EI%20need%20to%20match%20criteria%20on%20the%20column%20U%2C%20and%20have%20written%20a%20Boolean%20if%20statement%20(see%20below)to%20match%20on%20the%20desired%20ranges%20and%20place%20the%20appropriate%20value%20in%20column%20X%20which%20would%20be%201-8.%26nbsp%3B%20As%20you%20can%20see%20below%2C%20the%20formula%20works%20fine%20on%20rows%201%2C2%2C3%20and%20when%20it%20hits%20row%204%2C%20the%20formula%20breaks%2C%20then%20adds%20the%20value%20of%201%20on%20the%20remaining%20columns%20which%20should%20be%206%2C7%2C8.%26nbsp%3B%20I%20suspect%20that%20the%20if%20statement%20for%20some%20reason%20is%20only%20looking%20at%20the%20first%202%20digits%20of%20column%20U%20because%20row%204-9%20is%20where%20the%203%20digit%20ranges%20start%2C%20and%20I%20get%20a%20failure%20due%20to%20the%20formula%20being%20%3D%26gt%3B96%20and%20%26lt%3B128%2C%20which%20I%20suspect%20Excel%20is%20reading%20%3D%26gt%3B96%20and%20%26lt%3B12%20which%20generates%20the%20value%20of%20false%20and%20if%20it%20is%20indeed%20only%20reading%20the%20first%202%20digits%20that%20would%20explain%20the%20values%20of%201%20for%20160%2C%20192%2C%20224%2C%20255.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3D%3C%2FP%3E%3CP%3EIF(AND(U2%20%26gt%3B%3D%20%220%22%2CU2%20%26lt%3B%20%2232%22)%2C1%2C%3C%2FP%3E%3CP%3EIF(AND(U2%20%26gt%3B%3D%20%2232%22%2CU2%20%26lt%3B%20%2264%22)%2C2%2C%3C%2FP%3E%3CP%3EIF(AND(U2%20%26gt%3B%3D%20%2264%22%2CU2%20%26lt%3B%20%2296%22)%2C3%2C%3C%2FP%3E%3CP%3EIF(AND(U2%20%26gt%3B%3D%20%2296%22%2CU2%20%26lt%3B%20%22128%22)%2C4%2C%3C%2FP%3E%3CP%3EIF(AND(U2%20%26gt%3B%3D%20%22128%22%2CU2%20%26lt%3B%20%22160%22)%2C5%2C%3C%2FP%3E%3CP%3EIF(AND(U2%20%26gt%3B%3D%20%22160%22%2CU2%20%26lt%3B%20%22192%22)%2C6%2C%3C%2FP%3E%3CP%3EIF(AND(U2%20%26gt%3B%3D%20%22192%22%2CU2%20%26lt%3B%20%22224%22)%2C7%2C%3C%2FP%3E%3CP%3EIF(AND(U2%20%26gt%3B%3D%20%22224%22%2CU2%20%26lt%3B%20%22256%22)%2C8%3C%2FP%3E%3CP%3E))))))))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETest%20data%20is%20attached.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20ideas%20as%20to%20how%20to%20solve%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2331694%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2331762%22%20slang%3D%22en-US%22%3ERe%3A%20IF%20statement%20issue%20appears%20to%20be%20only%20reading%202%20digits%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2331762%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1046993%22%20target%3D%22_blank%22%3E%40MarkintheHV%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20problem%20is%20in%20the%20workbook%2C%20not%20in%20the%20picture%2C%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2331782%22%20slang%3D%22en-US%22%3ERe%3A%20IF%20statement%20issue%20appears%20to%20be%20only%20reading%202%20digits%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2331782%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1046993%22%20target%3D%22_blank%22%3E%40MarkintheHV%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20guess%20you%20work%20with%20numbers%2C%20if%20so%20correct%20one%20will%20be%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3EIF(AND(U2%20%26gt%3B%3D%200%2CU2%20%26lt%3B%2032)%2C1%2C%0AIF(AND(U2%20%26gt%3B%3D%2032%2CU2%20%26lt%3B%2064)%2C2%2C%0AIF(AND(U2%20%26gt%3B%3D%2064%2CU2%20%26lt%3B%2096)%2C3%2C%0AIF(AND(U2%20%26gt%3B%3D%2096%2CU2%20%26lt%3B%20128)%2C4%2C%0AIF(AND(U2%20%26gt%3B%3D%20128%2CU2%20%26lt%3B%20160)%2C5%2C%0AIF(AND(U2%20%26gt%3B%3D%20160%2CU2%20%26lt%3B%20192)%2C6%2C%0AIF(AND(U2%20%26gt%3B%3D%20192%2CU2%20%26lt%3B%20224)%2C7%2C%0AIF(AND(U2%20%26gt%3B%3D%20224%2CU2%20%26lt%3B%20256)%2C8%0A))))))))%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Eor%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DLOOKUP(U2%2C%0A%20%20%20%20%20%20%20%7B0%2C32%2C64%2C96%2C128%2C160%2C192%2C224%2C256%7D%2C%0A%20%20%20%20%20%20%20%7B1%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C0%7D)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2331844%22%20slang%3D%22en-US%22%3ERe%3A%20IF%20statement%20issue%20appears%20to%20be%20only%20reading%202%20digits%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2331844%22%20slang%3D%22en-US%22%3EInterestingly%20when%20I%20remove%20the%20quotes%20as%20illustrated%20above%2C%20all%20the%20values%20return%20as%20false.%20I%20have%20verified%20the%20formatting%20of%20the%20cells%20and%20they%20are%20all%20formatted%20as%20number%3C%2FLINGO-BODY%3E
New Contributor

I need to match criteria on the column U, and have written a Boolean if statement (see below)to match on the desired ranges and place the appropriate value in column X which would be 1-8.  As you can see below, the formula works fine on rows 1,2,3 and when it hits row 4, the formula breaks, then adds the value of 1 on the remaining columns which should be 6,7,8.  I suspect that the if statement for some reason is only looking at the first 2 digits of column U because row 4-9 is where the 3 digit ranges start, and I get a failure due to the formula being =>96 and <128, which I suspect Excel is reading =>96 and <12 which generates the value of false and if it is indeed only reading the first 2 digits that would explain the values of 1 for 160, 192, 224, 255.

 

=

IF(AND(U2 >= "0",U2 < "32"),1,

IF(AND(U2 >= "32",U2 < "64"),2,

IF(AND(U2 >= "64",U2 < "96"),3,

IF(AND(U2 >= "96",U2 < "128"),4,

IF(AND(U2 >= "128",U2 < "160"),5,

IF(AND(U2 >= "160",U2 < "192"),6,

IF(AND(U2 >= "192",U2 < "224"),7,

IF(AND(U2 >= "224",U2 < "256"),8

))))))))

 

Test data is attached.

 

Any ideas as to how to solve this?

5 Replies

@MarkintheHV 

The problem is in the workbook, not in the picture,

@MarkintheHV 

I guess you work with numbers, if so correct one will be

IF(AND(U2 >= 0,U2 < 32),1,
IF(AND(U2 >= 32,U2 < 64),2,
IF(AND(U2 >= 64,U2 < 96),3,
IF(AND(U2 >= 96,U2 < 128),4,
IF(AND(U2 >= 128,U2 < 160),5,
IF(AND(U2 >= 160,U2 < 192),6,
IF(AND(U2 >= 192,U2 < 224),7,
IF(AND(U2 >= 224,U2 < 256),8
))))))))

or

=LOOKUP(U2,
       {0,32,64,96,128,160,192,224,256},
       {1,2,3,4,5,6,7,8,0})
Interestingly when I remove the quotes as illustrated above, all the values return as false. I have verified the formatting of the cells and they are all formatted as number
Check your numbers in column U, make sure there aren't spaces with Char(32), or Char(160).
Char(32) can be removed by the TRIM Function
Char(160) can be removed by the SUBSTITUTE Function

=TRIM(SUBSTITUTE(U2,CHAR(160),))

Cheers

@MarkintheHV 

I see, that's since U2 is also the text, you need to convert it number to have correct results. That could be

=IF(AND(--U2 >= 0,--U2 < 32),1,
IF(AND(--U2 >= 32,--U2 < 64),2,
IF(AND(--U2 >= 64,--U2 < 96),3,
IF(AND(--U2 >= 96,--U2 < 128),4,
IF(AND(--U2 >= 128,--U2 < 160),5,
IF(AND(--U2 >= 160,--U2 < 192),6,
IF(AND(--U2 >= 192,--U2 < 224),7,
IF(AND(--U2 >= 224,--U2 < 256),8
))))))))

or

=LOOKUP(--U2,
       {0,32,64,96,128,160,192,224,256},
       {1,2,3,4,5,6,7,8,0})