Consulting

Results 1 to 7 of 7

Thread: Delete duplicate data useing VBA in Excel

  1. #1
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location

    Question Delete duplicate data useing VBA in Excel

    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 .

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,445
    Location
    What are the decision rules to get those results.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    I have 2 column , A and B and 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 .

  4. #4
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location
    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

  5. #5
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Thank you Dear vzachin ,

    I need VBA Code for this work .

    Thank you again .

  6. #6
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location
    parscon, if you record the macro, you will see how it works

    za

  7. #7
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •