Any way to extract associated values of cells that have the same name?

If I have a column A of names and another B with their associated values, how can I get the values which names contain, e.g. “Name1”. For example, let’s suppose:

Name1 | 23
Name3 | 45
Name1 | 28
Name4 | 2
Name2 | 7
Name1 | 4

What I want is a function that only shows a table with the values of “Name1”, ignoring the cells that don’t, without leaving blank rows:

23
28
4

I thought in BDEXTRACT() (see wiki) but I think it only applies to the value of a cell, not several.

What are you going to do with the obtained values? To summarize? Use the SUMIF() function. Print? Use TEXTJOIN(). Just extract? Use a filter. You are asking about the middle of your task, not about the problem as a whole. It looks like a problem XY

Duplicate of ¿Cómo extraer los valores asociados a unas celdas cuyos nombres coinciden?