Same value against each cell from a single column?

自作多情 提交于 2021-01-29 09:52:07

问题


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)<>":")

enter image description here




回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!