excel formula to check if value in range

radub

New Member
Joined
Sep 27, 2013
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi,
I am trying to figure out an excel 365 formula that can check if a number is in a list of numbers.
"list" is an excel column that contains both single values and intervals (e.g "80:81,441:443,500").
I was trying to use FILTERXML("<x><y>"&SUBSTITUTE(TEXTJOIN(" ",TRUE,D2),",","</y><y>")&"</y></x>","//y") to make a list into an array and then use ROW(INDIRECT(a:b)) to explode the a:b range
so far I came up with this one :
=SUM(--(IF(ISNUMBER(FIND(":",FILTERXML("<x><y>"&SUBSTITUTE(D2,",","</y><y>")&"</y></x>","//y"))),ROW(INDIRECT(FILTERXML("<x><y>"&SUBSTITUTE(D2,",","</y><y>")&"</y></x>","//y"))),NUMBERVALUE(FILTERXML("<x><y>"&SUBSTITUTE(D2,",","</y><y>")&"</y></x>","//y")))=H2))

but for some reason it can only see the first value in a range by using this formula.
1664782731296.png

any ideas are much apreciated
Thank you
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

If H2 was 442 would that count as being in the range?
Also do you have VSTACK & TEXTSPLIT functions yet?
 
Upvote 0
MrExcelPlayground12.xlsx
ABC
1InputSplit upCheck
280:82,441:444,50080442
381In list
482
5441
6442
7443
8444
9500
Sheet13
Cell Formulas
RangeFormula
B2:B9B2=LET(g,LEN(A2)-LEN(SUBSTITUTE(A2,",",""))+1, L,TRIM(MID(SUBSTITUTE($A2,",",REPT(" ",999)),SEQUENCE(g)*999-998,999)), d,NOT(ISERR(SEARCH(":",L))), colon,SEARCH(":",L), s,IF(d,VALUE(LEFT(L,colon-1)),VALUE(L)), t,IF(d,VALUE(RIGHT(L,LEN(L)-colon)),VALUE(L)), r,t-s+1, m,MAX(r), a,MOD(SEQUENCE(ROWS(s),m,0),m), b,IF(s+a>t,s,s+a), rb,ROWS(b), cb,COLUMNS(b), ar,SEQUENCE(rb*cb), sa,INDEX(b,INT((ar-1)/cb)+1,MOD((ar-1),cb)+1), UNIQUE(sa))
C3C3=LET(g,LEN(A2)-LEN(SUBSTITUTE(A2,",",""))+1, L,TRIM(MID(SUBSTITUTE($A2,",",REPT(" ",999)),SEQUENCE(g)*999-998,999)), d,NOT(ISERR(SEARCH(":",L))), colon,SEARCH(":",L), s,IF(d,VALUE(LEFT(L,colon-1)),VALUE(L)), t,IF(d,VALUE(RIGHT(L,LEN(L)-colon)),VALUE(L)), r,t-s+1, m,MAX(r), a,MOD(SEQUENCE(ROWS(s),m,0),m), b,IF(s+a>t,s,s+a), rb,ROWS(b), cb,COLUMNS(b), ar,SEQUENCE(rb*cb), sa,INDEX(b,INT((ar-1)/cb)+1,MOD((ar-1),cb)+1), IF(ISNA(MATCH(C2,sa,0)),"Not in list","In list"))
Dynamic array formulas.
 
Upvote 0
Solution
If you do have Vstack etc, how about
Fluff.xlsm
ABCDEFGH
1
280:81,441:443,500442442
Main
Cell Formulas
RangeFormula
F2F2=LET(a,DROP(REDUCE("",TEXTSPLIT(D2,,","),LAMBDA(a,b,LET(x,TEXTSPLIT(b,":",,1),VSTACK(a,IF(COLUMNS(x)>1,SEQUENCE(INDEX(x,1,2)-INDEX(x,1,1)+1,,INDEX(x,1,1)),x+0))))),1),FILTER(a,a=H2,0))
 
Upvote 0
Thany you so much guys!
@Fluff - unfortunately i don't have the insider version
@James - you solution does the trick.
i wasn't aware of this kind of power that LET function has.
Thank you once again.
 
Upvote 0
unfortunately i don't have the insider version
Those functions are now on general release for people on the monthly channel, so it maybe that you are on the semi-annual channel.
 
Upvote 0

Forum statistics

Threads
1,215,635
Messages
6,125,945
Members
449,275
Latest member
jacob_mcbride

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