Solved

vba code to keep unique data entries

Posted on 2014-03-11
4
226 Views
Last Modified: 2014-03-19
Hi Experts Excel 2007

Need vba code to do the following and apologies I cannot upload a sample file from my location.

Assume: table
Business Name.               Reference.
Abc.                                    Apple
Abc.                                    Orange
Dcf.                                    Bank
Edf.                                     Office
Edf.                                     Office

Based on the above table keep the unique values based on col d (reference) and delete the rest..in this case we have edf twice in col A and Office twice in col d so remove.

Need the macro to loop through 20000 rows of data..
Where there is a single line as with dcf keep in the table.
0
Comment
Question by:route217
  • 2
4 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39920022
HI,

pls try

Sub Macro()
Set myRange = Range(Range("D2"), Range("d" & Rows.Count).End(xlUp))
For Idx = myRange.Rows.Count + 1 To 2 Step -1
    If Application.WorksheetFunction.CountIf(myRange, Range("D" & Idx).Value) > 1 Then
        Range("D" & Idx).EntireRow.Delete
    End If
Next
End Sub

Open in new window

Regards
0
 
LVL 39

Expert Comment

by:nutsch
ID: 39920564
Have you tried the Remove Duplicates function in the Data Ribbon? (Alt+A M)

It seems to me it could help you in this case.

Thomas
0
 
LVL 39

Expert Comment

by:nutsch
ID: 39920573
I rgonzo's code works for you, I'd frame it with the following to speed up code execution significantly:

Application.screenupdating=false
'...
Application.screenupdating=true
0
 

Author Comment

by:route217
ID: 39925896
Excellent feedback
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question