Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

Excel VBA Code for concatenating data in multiple columns and removing duplicates

Example Photo

In reference to the attached "Example Photo" Image...

I would like to concatenate the unique data in Columns I and K into one cell (separated by line break) and remove the duplicated information in the other columns. My goal is to have the data look like rows 2 and 7 without the duplicated rows in between.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can download Power Query or if you have Excel 2016 it is a default its name is Get & Tranform in the Data Tab.

  1. Select any cell in your main table.
  2. Go to Power Query or Data and select From Table/Range.
  3. It will be a box with the range OK.

It will open the Query Editor

  1. Go to Home select Group by.
  2. In the Options:

    • Group by: Add all the fields you don't want to concatenate.
    • New Column name: It could be "Group".
    • Operation: Select All Rows.
    • OK.
  3. Go to Add Column select Custom Columna.

  4. Concatenate field Name

    [Column Named Step 5][Column Name where is the data to concatenate]

  5. Go to the new field and click in the right corner (Arrows) and select Extract Values....

  6. Select delimiter #(lf) OK.
  7. Go to Home tab and select Advanced Editor.
  8. There look for ""#(lf)"" and delete the extra "" it should be "#(lf)" click in Done.
  9. Got Home select Close & Load.

It will create a new sheet with a table with your new data.

  1. Use Wrap Text in Home tab to see the lines break.

You can append more data in the main table and it will be just a right click refresh in the Power Query Table and you will get your data.

I made this tutorial. It is in Spanish but I am using the English Excel version.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...