?
Solved

vba code to keep unique data entries

Posted on 2014-03-11
4
Medium Priority
?
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
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 a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

777 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