You are here:

- Home
- Computing/Technology
- Business Software
- Excel
- Delete duplicate entries

Advertisement

Dear Tom,

Thanks for your help yesterday, it solved the problem perfectly.

I now have another problem, I need to delete duplicate entries for column A and let the higher value of column B to be the remaining value. For example:

Column A B

1 4

1 2

2 5

2 9

3 10

3 10

becomes

Column A B

1 4

2 9

3 10

I have written the following VBA to solve the problem:

Sub comb()

Dim i As Long

i = 1

Do While Cells(i + 1, 9) <> ""

If Cells(i, 9) = Cells(i + 1, 9) Then

If Cells(i, 10) >= Cells(i + 1, 10) Then

Rows(i + 1).EntireRow.Delete

End If

If Cells(i, 10) < Cells(i + 1, 10) Then

Cells(i, 10) = Cells(i + 1, 10)

Rows(i + 1).EntireRow.Delete

End If

i = i + 1

End If

' If i > 1000 Then Exit Sub

Do While Cells(i, 9) <> Cells(i + 1, 9)

i = i + 1

Loop

Loop

End Sub

However, it does not solve multiple entries that has more than 2. I do not know how should I put in the loop for it.

Basically, after running, it will become like this:

Column A B

1 4

1 2

1 5

becomes

Column A B

1 4

1 5

instead of

Column A B

1 5

How should I put the loop so that it can remove more than 1 duplication?

Thank you so much for your time.

Donald,

This worked for me with the data you show:

Sub comb()

Dim i As Long

i = 1

Do While Cells(i + 1, 9) <> ""

If Cells(i, 9) = Cells(i + 1, 9) Then

If Cells(i, 10) >= Cells(i + 1, 10) Then

Rows(i + 1).EntireRow.Delete

ElseIf Cells(i, 10) < Cells(i + 1, 10) Then

Cells(i, 10) = Cells(i + 1, 10)

Rows(i + 1).EntireRow.Delete

End If

Else

i = i + 1

End If

Loop

End Sub

--

Regards,

Tom Ogilvy

- Add to this Answer
- Ask a Question

Rating(1-10) | Knowledgeability = 10 | Clarity of Response = 10 | Politeness = 10 |

Comment | Thanks a lot!! |

This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

Answers by Expert:

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Extensive experience. **Education/Credentials**

Master of Science (MS) degree Operations Research (ORSA)**Awards and Honors**

Microsoft MVP in Excel.