Loop through 2 columns and concatenate the values

2020-02-16 05:38发布

Workbook 1 Image

Workbook 2 Image after macro

I have a workbook with two sheets. Please check the images attached above.

Worksheet 1:

ABC Min: $100
ABC Total: $150
ABC Avg: $125
BCD Min: $100
BCD Total: $150
BCD Avg: $125

I want a macro to loop through the columns, Concatenate (With $ values) and insert into worksheet 2. Something like this:

ABC "Min: $100 
    Total: $150
    Avg: $125"
BCD "Min: $100 
    Total: $150
    Avg: $125"

标签: excel vba
1条回答
乱世女痞
2楼-- · 2020-02-16 06:32

You can do something like this, done on 1 sheet, but index and match will work across sheets. Cell E1 is data validation to choose either case, can add more as needed. Cells A4:B9 contain the lookup and the match builds the lookup value.

=INDEX(B$4:B$9,MATCH(E$1&" "&E4,A$4:A$9,0))

enter image description here

查看更多
登录 后发表回答