PDA

View Full Version : Solved: Delete duplicate data useing VBA in Excel



parscon
02-10-2012, 06:44 AM
Hi , I have a problem in exel with VBA .

in column A i have same data like :

A1= 1
A2= 1
A3= 1
A4= 2
A5 = 3
A6= 3
A7 = 4
A8 = Book
A9 = Book
A10 = Car

I need a macro show me this results
A4= 2
A7 = 4
A10 = Car

please help me with VBA .

Thank you so much .

Bob Phillips
02-10-2012, 06:55 AM
What are the decision rules to get those results.

parscon
02-10-2012, 07:12 AM
I have 2 column , A and B amd want to compare them and Unique data will be in column C ,

but there is a Problem with compare the number of row are not same and are not sort .
Like :

column A
A1 : 1
A2:2
A3: Book
A4:Cat
A5:3

column B
B1: 2
B2: 3

Must Be : That I need

Column C

C1:1
C2: Book
C3: Cat


Hope you understand what i need .

Thank you agaian for yourt help .

vzachin
02-10-2012, 07:37 AM
parscon,
just a thought. if you combine column a & b and place that into column c, you can do an advanced filter unique records only

za

parscon
02-10-2012, 07:44 AM
THank you Dear vzachin ,

I need VBA Code fo this work .

THank you again .

vzachin
02-10-2012, 07:50 AM
parscon, if you record the macro, you will see how it works

za

parscon
02-10-2012, 08:28 AM
Here is the code for anyone that need like my request .



Sub removematches()
Dim firstcolumn() As Variant
Dim colA As Range
Dim colB As Range
Dim i As Long, del As Long
'This will set the ranges to look in. Note that this will only work for data with no blank cells. If you have blank cells, you can change these Set statements to the following:
' Set colA = Range("A1:A100") if you have 100 rows you want to look at.
Set colA = Range("A1", Range("A1").End(xlDown))
Set colB = Range("B1", Range("B1").End(xlDown))
firstcolumn = colA
ReDim Preserve firstcolumn(1 To UBound(firstcolumn), 1 To 2) As Variant
i = 1
del = 0
Do While i <= UBound(firstcolumn)
firstcolumn(i, 2) = Application.WorksheetFunction.CountIf(colB, firstcolumn(i, 1))
If firstcolumn(i, 2) > 0 Then
Range("A1").Offset(i - del - 1, 0).Delete Shift:=xlUp
del = del + 1
End If
i = i + 1
Loop