+ Reply to Thread
Results 1 to 3 of 3

Compare fields and if match found move data and delete row

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-16-2006
    Posts
    241

    Compare fields and if match found move data and delete row

    I need a vba solution for the following:

    I have a spreadsheet where I need to compare fields in columns A & B and if they match one another then remove the duplicates but put the data from the duplicates in columns d & f. I have attached an example of what I am looking for. Any help would be appreciated.


    [attach]example.xlsx[/attach]



    Thanks,

    Met
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,588

    Re: Compare fields and if match found move data and delete row

    Try
    Sub test()
        Dim a, i As Long, ii As Long, txt As String, dic As Object
        Set dic = CreateObject("Scripting.Dictionary")
        dic.CompareMode = 1
        a = Sheets("data").Cells(1).CurrentRegion.Resize(, 7).Value
        ReDim Preserve a(1 To UBound(a, 1), 1 To UBound(a, 2) + 1)
        For i = 1 To UBound(a, 1)
            txt = Join(Array(a(i, 1), a(i, 2), a(i, 6), a(i, 7)), Chr(2))
            If Not dic.exists(txt) Then
                dic(txt) = dic.Count + 1: a(dic.Count, UBound(a, 2)) = 3
                For ii = 1 To UBound(a, 2) - 1
                    a(dic.Count, ii) = a(i, ii)
                Next
            Else
                a(dic(txt), UBound(a, 2)) = a(dic(txt), UBound(a, 2)) + 1
                a(dic(txt), a(dic(txt), UBound(a, 2))) = a(i, 3)
            End If
        Next
        Sheets.Add.Cells(1).Resize(dic.Count, UBound(a, 2) - 1).Value = a
    End Sub

  3. #3
    Forum Contributor
    Join Date
    02-16-2006
    Posts
    241

    Re: Compare fields and if match found move data and delete row

    Thanks that did it.

    Met

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. to compare between two workbooks and retrieve data..if match is found
    By killer12 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-20-2014, 11:18 AM
  2. [SOLVED] Compare two columns and copy and paste data from a third column when a match is found
    By GatorsBucs in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-28-2013, 06:54 PM
  3. [SOLVED] Compare two columns with data, if match or not found then change the colour of cells
    By Sachy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-15-2013, 03:58 AM
  4. Replies: 6
    Last Post: 05-24-2012, 09:14 AM
  5. Compare Data in 2 sheets and delete or move rows
    By tracktor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-21-2011, 12:21 AM
  6. Compare two sheets and delete row if match found
    By Steinwall in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-13-2011, 03:25 PM
  7. How to compare to fields and move data?
    By Brian in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-03-2005, 04:29 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1