+ Reply to Thread
Results 1 to 3 of 3

Compare Two Spreadsheets and Delete Row IF

Hybrid View

  1. #1
    Registered User
    Join Date
    06-25-2012
    Location
    Indiana, USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Compare Two Spreadsheets and Delete Row IF

    I have two spreadsheets, they are almost identical except for one column.

    I want to be able to search Column A of sheet1 to match Column A in sheet2.
    If there is a match, I would like to search Column F in sheet2 for a certain word for the same row of the match in Column A. If that word is in column F for the matching row, I would like to delete the matching row from sheet1

    Any Ideas?

  2. #2
    Registered User
    Join Date
    06-19-2012
    Location
    Canada Eh
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    40

    Re: Compare Two Spreadsheets and Delete Row IF

    Hi fieldannie22, The following is not tested and I am unsure what it is you want when you find a match in the A columns but this is a start:
    Option Explicit
    
    Sub CompareColumns()
        Dim ws1 As Worksheet, ws2 As Worksheet
        Dim s1Rng As Range, s2Rng As Range, oCell1 As Range, oCell2 As Range
        
        Set ws1 = Worksheets("Sheet1")
        Set ws2 = Worksheets("Sheet2")
        Set s1Rng = ws1.Range(ws1.Cells(1, 1), ws1.Cells(ws1.Rows.Count, 1).End(xlUp))
        Set s2Rng = ws2.Range(ws2.Cells(1, 1), ws2.Cells(ws2.Rows.Count, 1).End(xlUp))
        
        For Each oCell1 In s1Rng
            For Each oCell2 In s2Rng
                If oCell2.Value = oCell1.Value Then
                    'Not sure what you want here but this is a start'
                End If
            Next oCell2
        Next oCell1
    End Sub
    EF killed Mordred

    46 & 2 is just ahead of me!

  3. #3
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    883

    Re: Compare Two Spreadsheets and Delete Row IF

    Cross-posted here

    http://www.mrexcel.com/forum/showthr...-Delete-Row-IF
    Last edited by WasWodge; 06-29-2012 at 03:11 PM.
    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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