Consulting

Results 1 to 4 of 4

Thread: Solved: compare two columns and delete matches

  1. #1

    Solved: compare two columns and delete matches

    I would like to compare column D and column F.
    If the content in a cell in column F matches with a cell content in column D,
    Then delete the cell in column F
    Also delete the corresponding cell in column G
    Take a look at the image below
    http://www.iimmgg.com/image/73485183...2d38e37c7dd8c2

    I have attached a sample workbook
    Sheet 1 contains the initial set of data
    Sheet 2 contains a button to insert the codes
    Sheet 3 shows how the final output looks like
    deleteMatch.xls

  2. #2
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    Your result sheet left out some matching results so not sure of your requirement. See if this works:
    [VBA]Private Sub CommandButton1_Click()
    Dim LastRowD, LastRowF As Long
    With Sheet1
    LastRowD = .Range("D" & Rows.Count).End(xlUp).Row
    For i = 1 To LastRowD
    LastRowF = .Range("F" & Rows.Count).End(xlUp).Row
    MyVal = .Range("D" & i).Value
    For j = LastRowF To 1 Step -1
    If .Range("F" & j).Value = MyVal Then
    .Range("F" & j).Resize(, 2).Delete Shift:=xlUp
    End If
    Next j
    Next i
    End With
    End Sub[/VBA]
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  3. #3
    Thanks Shrivallabha for your help. It works. I think i missed out the other matches.

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Hi rafi,

    Try the attached.
    Attached Files Attached Files
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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