+ Reply to Thread
Results 1 to 5 of 5

Delete Non matching dates

Hybrid View

Trevasaurus Delete Non matching dates 04-15-2013, 02:20 PM
xladept Re: Delete Non matching dates 04-15-2013, 02:43 PM
Trevasaurus Re: Delete Non matching dates 04-15-2013, 03:49 PM
xladept Re: Delete Non matching dates 04-15-2013, 03:55 PM
Trevasaurus Re: Delete Non matching dates 04-15-2013, 04:04 PM
  1. #1
    Forum Contributor
    Join Date
    10-16-2012
    Location
    Brooklyn
    MS-Off Ver
    Excel 2010 PC
    Posts
    137

    Delete Non matching dates

    Hi.

    I have two columns of dates in two separate worksheets. Both sets of dates are in Column A of worksheets 1 and 2. I'm trying to compare the dates in worksheet 1 and 2, keeping the ones that exist in both sheets, and delete the ones that exist on just one sheet.
    Is there an easy way to do this?

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Delete Non matching dates

    Hi Treva,

    Here's one way:

    Sub UniquA(): Dim A1 As Range, A2 As Range, w1 As Worksheet, w2 As Worksheet
    Dim r As Long: Set w1 = Sheets("Sheet1"): Set w2 = Sheets("Sheet2")
    
    For Each A1 In w1.Range("A1:A" & w1.Range("A" & Rows.Count).End(xlUp).row)
    
    For Each A2 In w2.Range("A1:A" & w2.Range("A" & Rows.Count).End(xlUp).row)
    If A2 = A1 Then GoTo GetNext
    Next
    A1 = ""
    GetNext: Next
    
    For Each A2 In w2.Range("A1:A" & w2.Range("A" & Rows.Count).End(xlUp).row)
    For Each A1 In w1.Range("A1:A" & w1.Range("A" & Rows.Count).End(xlUp).row)
    If A2 = A1 Then GoTo GetAnother
    Next
    A2 = ""
    GetAnother: Next
    
    For r = w1.Range("A" & Rows.Count).End(xlUp).row To 1
    If w1.Range("A" & r) = "" Then w1.Range("A" & r).EntireRow.Delete Shift:=xlUp
    Next
    
    For r = w2.Range("A" & Rows.Count).End(xlUp).row To 1
    If w2.Range("A" & r) = "" Then w2.Range("A" & r).EntireRow.Delete Shift:=xlUp
    Next
    
    End Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Contributor
    Join Date
    10-16-2012
    Location
    Brooklyn
    MS-Off Ver
    Excel 2010 PC
    Posts
    137

    Re: Delete Non matching dates

    Thanks xladept. This works perfectly.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Delete Non matching dates

    You're welcome - you could probably adapt this code to the other post?

  5. #5
    Forum Contributor
    Join Date
    10-16-2012
    Location
    Brooklyn
    MS-Off Ver
    Excel 2010 PC
    Posts
    137

    Re: Delete Non matching dates

    Yes, I did. Thanks.

+ 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