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

Dazzybeeguy

Board Regular
Joined
Jan 6, 2022
Messages
111
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
 
Not sure what you mean by that - could you possibly upload a screenshot what the problem is with the calculation?
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Not sure what you mean by that - could you possibly upload a screenshot what the problem is with the calculation?
If the list of names changes, so that it goes from A2:A5 one day and another day it expands to A2:A15 how can i account for this in the formula, if i manually change it in the formula it works, if i change it to A2:A15 to cover all eventualities it doesn't work right unless the range is populated with names
 
Upvote 0
Try replacing...

Excel Formula:
names, A2:A5,

with

Excel Formula:
names, A2:INDEX(A:A, MATCH(REPT("z", 255), A:A, 1)),

Hope this helps!
 
Upvote 0
For what it's worth, here's a formula similar to the ones from both @hagia_sofia and @Scott R . . .


Excel Formula:
=LET(
    names, A2:INDEX(A:A, MATCH(REPT("z", 255), A:A, 1)),
    cities, B2:B26,
    criteria, "Liverpool",
    array, SCAN(
        0,
        SEQUENCE(ROWS(cities)),
        LAMBDA(i, a, COUNTIFS(TAKE(cities, a), criteria))
    ),
    indexes, MOD(array - 1, ROWS(names)) + 1,
    resultArray, IF(cities = criteria, INDEX(names, indexes), ""),
    resultArray
)
 
Upvote 0
For what it's worth, here's a formula similar to the ones from both @hagia_sofia and @Scott R . . .


Excel Formula:
=LET(
    names, A2:INDEX(A:A, MATCH(REPT("z", 255), A:A, 1)),
    cities, B2:B26,
    criteria, "Liverpool",
    array, SCAN(
        0,
        SEQUENCE(ROWS(cities)),
        LAMBDA(i, a, COUNTIFS(TAKE(cities, a), criteria))
    ),
    indexes, MOD(array - 1, ROWS(names)) + 1,
    resultArray, IF(cities = criteria, INDEX(names, indexes), ""),
    resultArray
)
Thats great, thanks
 
Upvote 0
You just need to extend the 'names' range in the formula.

for my solution:
Excel Formula:
=LET( names, $A$2:$A$15,     IF( B2 = "Liverpool", INDEX( names, MOD( COUNTIF( B$2:B2, "Liverpool" ) - 1, ROWS( names )) + 1 ), "" ))

for Hagia's solution:
Excel Formula:
=LET(
city,"Liverpool",
names,A2:A15,
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
@Scott R

It looks like you may have missed this part of the original post...

. . . if i change it to A2:A15 to cover all eventualities it doesn't work right unless the range is populated with names

Hence the use of a dynamic reference so that the range will automatically adjust as new data is added and avoid having empty cells.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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