问题
I have one column like below:
Fruits:
Apple
Banana
Mango
Vegetables:
Broccoli
Tomato
Potatoes
I would like each value to have their parent name next to it in the cell like below:
Apple Fruit
Banana Fruit
Mango Fruit
Broccoli Vegetables
Tomato Vegetables
Potatoes Vegetables
How can I achieve this?
回答1:
As per my below screenshot put below formula to B1 cell.
=IF(RIGHT(A2,1)=":",LEFT(A2,LEN(A2)-1),B1)
Then put following formula to C1 cell
=FILTER(A2:B9,RIGHT(A2:A9,1)<>":")
回答2:
If your data is in column A, I am able to get the result with a helper column, by using the following formula in B1
:
=FILTER($A:$A,($A:$A<>"")*(RIGHT($A:$A,1)<>":"))
This will result in your data excluding the titles (fruit, vegetable).
Then in C1
use the following formula and drag down:
=IFERROR(B1&" "&SUBSTITUTE(LOOKUP(2,1/(RIGHT(INDIRECT("$A$1:$A"&MATCH(B1,$A:$A,0)),1)=":"),INDIRECT("$A$1:$A"&MATCH(B1,$A:$A,0))),":",""),"")
来源:https://stackoverflow.com/questions/65741687/same-value-against-each-cell-from-a-single-column