5 Quick Ways to Combine Duplicate Rows in Excel

Excel is a powerhouse for data manipulation, but duplicate rows can quickly clutter your spreadsheets and skew your analysis. Whether you’re dealing with imported data, manual entries, or accidental duplicates, knowing how to efficiently combine these rows is crucial. Here are five quick and effective methods to tackle duplicate rows in Excel, ensuring your data remains clean and actionable.
1. Use the “Remove Duplicates” Feature (Simplest Method)
Excel’s built-in Remove Duplicates tool is the easiest way to eliminate exact duplicates. However, if you want to combine data from duplicate rows (e.g., summing values), this method falls short. Here’s how to use it:
- Select the range of data containing duplicates.
- Go to the Data tab and click Remove Duplicates.
- Choose the columns to check for duplicates and click OK.
Best For: Quickly removing exact duplicates without combining data.
2. Consolidate Data with PivotTables (Most Versatile)
PivotTables are a dynamic way to combine duplicate rows based on specific criteria. For example, you can sum, count, or average values in duplicate rows.
- Select your data and go to the Insert tab.
- Click PivotTable and choose the destination.
- Drag the column with duplicates to the Rows area and the value column to the Values area.
- Choose the aggregation method (e.g., Sum, Count) from the dropdown menu.
PivotTables are ideal for aggregating data from duplicate rows while retaining flexibility for further analysis.
3. Merge Rows with Power Query (Advanced and Automated)
Power Query is Excel’s most robust tool for data transformation. It allows you to group and aggregate duplicate rows efficiently.
- Select your data and go to the Data tab.
- Click From Table/Range to load the data into Power Query.
- In the Power Query Editor, select the columns to group by and the column to aggregate.
- Go to Transform > Group By and choose the aggregation method (e.g., Sum, Count).
- Click Close & Load to return the cleaned data to Excel.
Pros: Automates data cleaning and handles complex transformations.
Cons: Requires familiarity with Power Query.
4. Combine Rows with Formulas (Manual but Flexible)
If you prefer not to use built-in tools, formulas like SUMIFS
, COUNTIFS
, or AGGREGATE
can help combine data from duplicate rows.
- Identify the column with duplicates (e.g., Column A) and the value column (e.g., Column B).
- In a new column, use a formula like:
=SUMIFS(B:B, A:A, A2)
- Copy the formula down to apply it to all unique rows.
Best For: Small datasets or specific aggregation needs.
5. Use VBA Macros (Automated and Customizable)
For repetitive tasks, VBA macros can automate the process of combining duplicate rows. Here’s a simple example:
- Press Alt + F11 to open the VBA editor.
- Insert a new module and paste the following code:
Sub CombineDuplicates() Dim rng As Range Set rng = Selection rng.RemoveDuplicates Columns:=1, Header:=xlYes End Sub
- Run the macro to remove duplicates or modify the code to aggregate data.
VBA is powerful but requires programming knowledge. Use it for complex or recurring tasks.
How do I combine duplicate rows without losing data?
+Use PivotTables or Power Query to aggregate data from duplicate rows while retaining unique values.
Can I combine duplicate rows across multiple columns?
+Yes, use Power Query’s Group By feature or PivotTables to handle multiple columns.
What’s the fastest way to remove duplicates in Excel?
+The built-in Remove Duplicates feature under the Data tab is the quickest method.
How do I automate duplicate row consolidation?
+Use Power Query for recurring tasks or write a VBA macro for custom automation.
By mastering these methods, you can efficiently combine duplicate rows in Excel, ensuring your data remains clean, organized, and ready for analysis. Whether you’re a beginner or an advanced user, there’s a solution tailored to your needs.