count certain numbers in a string of 12 numbers

Marshall1970

New Member
Joined
Jun 29, 2005
Messages
36
I have a field that contains the following: 012100002030

I need a formula that will tell me whether or not the string contains a number higher than 2 or whether or not it contains more than one 2.

Examples:

001000002011
111111000022
401110000000

the first loan would not meet the criteria as it contains no number higher than 2 and only contains one 2.
the second loan would meet the criteria as it contains two 2's.
the 3rd loan would meet the criteria as it contains a number higher than 2.

thank you, hopefully I have provided enough info.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try:

Code:
=OR(SUMPRODUCT(--(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)+0=2))>=2,SUMPRODUCT(--(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)+0>2)))
 
Upvote 0
one more thing, if I want the value to return "Yes" instead of TRUE or "No" instead of FALSE, how would I do that?
 
Upvote 0
ok, thanks all that works great. One more twist..

if the first digit is a 1, then I want to say "Exclude" regardless of any other digits
if the last digit is a 2 and all other digits are 0, then I want it to say "Include"

Examples:

000000000002 - include
111111111111 - include
200000300000 - exclude
100000000000 - exclude
000003000000 - exclude
000020000020 - exclude
 
Upvote 0
Wrap two more IF statements around your formula:

=IF(LEFT(A1,1)+0=1,"Exclude",IF(RIGHT(A1,1)+0=2,"Include",IF( *insert formula *,"YES","No")))
 
Upvote 0
so close, if I include only the first if statement, it works. when i put in the 2nd if I get an errror msg..any ideas?


=IF(LEFT(AT2,1)+0=1,"IneligiblePmtHist",if(right(AT2,1)+0=2,"IneligiblePmtHist",IF(OR(SUMPRODUCT(--(MID(AT2,ROW(INDIRECT("1:"&LEN(AT2))),1)+0=2))>=2,SUMPRODUCT(--(MID(AT2,ROW(INDIRECT("1:"&LEN(AT2))),1)+0>2))),"IneligiblePmtHist",""))
 
Upvote 0
My bad... it's exceeding the limit of 7 nested functions.

But, because they all return the same thing, you can combine them:

=IF(OR(LEFT(AT2,1)+0=1,RIGHT(AT2,1)+0=2,SUMPRODUCT(--(MID(AT2,ROW(INDIRECT("1:"&LEN(AT2))),1)+0=2))>=2,SUMPRODUCT(--(MID(AT2,ROW(INDIRECT("1:"&LEN(AT2))),1)+0>2))),"IneligiblePmtHist","")
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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