Assign next in list if a criteria is met. See Beatles example

Dazzybeeguy

Board Regular
Joined
Jan 6, 2022
Messages
113
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Column A2:A6 is the names
B:B is a list of cities
In Column C in C2 down I want a formula that would look to see if the City is Liverpool and if so assign it to the 1st person in the list of names, on the next row if its Liverpool assign that to the next person and so on.

NamesCitiesResults list
JohnLiverpool
GeorgeLeeds
PaulLuton
RingoManchester
Burnley
LiverpoolJohn
LiverpoolGeorge
Chester
York
Liverpool
London
Hull
LiverpoolPaul
Leeds
LiverpoolRingo
Luton
LiverpoolJohn
LiverpoolGeorge
Leeds
Luton
Manchester
Burnley
LiverpoolPaul
LiverpoolRingo
Chester
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hello, test this:

Excel Formula:
=LET(
city,"Liverpool",
names,A2:A5,
a,B2:B26,
r,ROWS(names),
b,SCAN(0,SEQUENCE(ROWS(a)),LAMBDA(x,y,COUNTIFS(TAKEa,y),city))),
c,IF(a=city,b,""),
d,TOCOL(IF(SEQUENCE(,MAX(b)/r+1),names),,TRUE),
e,SEQUENCE(ROWS(d)),
XLOOKUP(c,e,d,""))
 
Upvote 0
Hello, test this:

Excel Formula:
=LET(
city,"Liverpool",
names,A2:A5,
a,B2:B26,
r,ROWS(names),
b,SCAN(0,SEQUENCE(ROWS(a)),LAMBDA(x,y,COUNTIFS(TAKEa,y),city))),
c,IF(a=city,b,""),
d,TOCOL(IF(SEQUENCE(,MAX(b)/r+1),names),,TRUE),
e,SEQUENCE(ROWS(d)),
XLOOKUP(c,e,d,""))
I get the error you have entered too few arguments and it highlights city
=LET(
city,"Liverpool",
names,A2:A5,
a,B2:B26,
r,ROWS(names),
b,SCAN(0,SEQUENCE(ROWS(a)),LAMBDA(x,y,COUNTIFS(TAKEa,y),city))),
c,IF(a=city,b,""),
d,TOCOL(IF(SEQUENCE(,MAX(b)/r+1),names),,TRUE),
e,SEQUENCE(ROWS(d)),
XLOOKUP(c,e,d,""))
 
Upvote 0
It seems that there was a missing parenthesis (my bad):

Excel Formula:
=LET(
city,"Liverpool",
names,A2:A5,
a,B2:B26,
r,ROWS(names),
b,SCAN(0,SEQUENCE(ROWS(a)),LAMBDA(x,y,COUNTIFS(TAKE(a,y),city))),
c,IF(a=city,b,""),
d,TOCOL(IF(SEQUENCE(,MAX(b)/r+1),names),,TRUE),
e,SEQUENCE(ROWS(d)),
XLOOKUP(c,e,d,""))
 
Upvote 0
Solution
It seems that there was a missing parenthesis (my bad):

Excel Formula:
=LET(
city,"Liverpool",
names,A2:A5,
a,B2:B26,
r,ROWS(names),
b,SCAN(0,SEQUENCE(ROWS(a)),LAMBDA(x,y,COUNTIFS(TAKE(a,y),city))),
c,IF(a=city,b,""),
d,TOCOL(IF(SEQUENCE(,MAX(b)/r+1),names),,TRUE),
e,SEQUENCE(ROWS(d)),
XLOOKUP(c,e,d,""))
Thanks that does the trick
 
Upvote 0
Or this in C2 for a non-dynamic array formula that would need to be copied down:
Excel Formula:
=IF( B2 = "Liverpool", INDEX( $A$2:$A$5, MOD( COUNTIF( B$2:B2, "Liverpool" ) - 1, 4 ) + 1 ), "" )
 
Upvote 0
It seems that there was a missing parenthesis (my bad):

Excel Formula:
=LET(
city,"Liverpool",
names,A2:A5,
a,B2:B26,
r,ROWS(names),
b,SCAN(0,SEQUENCE(ROWS(a)),LAMBDA(x,y,COUNTIFS(TAKE(a,y),city))),
c,IF(a=city,b,""),
d,TOCOL(IF(SEQUENCE(,MAX(b)/r+1),names),,TRUE),
e,SEQUENCE(ROWS(d)),
XLOOKUP(c,e,d,""))
I just noticed one issue, if I add names to the list so names so I change names from A2:A5 to A2:A15 it doesnt work properly it misses loads out, what else needs to change in the formula to fix this ?
 
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,603
Members
452,660
Latest member
Zatman

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