How to compare 2 different excel sheets and output results on 3rd sheet

sunwave

New Member
Joined
Feb 28, 2024
Messages
9
Office Version
  1. 365
Platform
  1. Windows
I want to compare the email addresses on sheet1 to sheet 2 and output the results on sheet 3.

Sheet 1 and Sheet 2 have most of the same email addresses with a few extras (different addresses) on each.
There are extra email addresses on sheet 1 but are not on sheet 2.
There are extra email addresses on sheet 2 but are not on sheet 1. (Vice versa)

The results:
I want the results to output the email addresses from sheet 1, that are missing from sheet 2, labeled as "Not in Sheet 2"
I want the results to output the email addresses from sheet 2, that are missing from sheet 1, labeled as "Not in sheet 1" (Vice Versa)
The results from both sheets should output on Sheet 3.


Images of Sheet 1, Sheet 2, Sheet 3, are provided below.

How would I code this? Thank you!!
 

Attachments

  • sheet1.PNG
    sheet1.PNG
    73.2 KB · Views: 16
  • sheet2.PNG
    sheet2.PNG
    71.8 KB · Views: 16
  • results.PNG
    results.PNG
    27 KB · Views: 14

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
There's a number of ways you could do this, here's just one. Please try on a copy of your workbook. Assumes your layout is exactly as you images suggest, and that the code names of the sheets match the sheet tab names.

VBA Code:
Sub Copy_Emails()
    Application.ScreenUpdating = False
    With Sheet1
        If .AutoFilterMode Then .AutoFilter.ShowAllData
        With .Range("E2:E" & .Cells(Rows.Count, "D").End(xlUp).Row)
            .Value = Evaluate("IF(ISNA(MATCH(" & .Offset(, -1).Address(, , , 1) & ",Sheet2!B:B,0)),""Not in Sheet 2"","""")")
        End With
        With .Range("A1").CurrentRegion
            .AutoFilter 5, "<>"
            If .SpecialCells(xlCellTypeVisible).Address <> .Rows(1).Address Then
                .Offset(1, 3).Resize(.Rows.Count - 1, 2).Copy Sheet3.Cells(Rows.Count, 1).End(xlUp).Offset(1)
                .AutoFilter
            End If
        End With
        .Columns("E").ClearContents
    End With
    
    With Sheet2
        If .AutoFilterMode Then .AutoFilter.ShowAllData
        With .Range("E2:E" & .Cells(Rows.Count, "B").End(xlUp).Row)
            .Value = Evaluate("IF(ISNA(MATCH(" & .Offset(, -3).Address(, , , 1) & ",Sheet1!D:D,0)),""Not in Sheet 1"","""")")
        End With
        With .Range("A1").CurrentRegion
            .AutoFilter 5, "<>"
            If .SpecialCells(xlCellTypeVisible).Address <> .Rows(1).Address Then
                .Columns("C:D").Hidden = True
                .Offset(1, 1).Resize(.Rows.Count - 1, 4).Copy Sheet3.Cells(Rows.Count, 1).End(xlUp).Offset(1)
                .Columns("C:D").Hidden = False
                .AutoFilter
            End If
        End With
        .Columns("E").ClearContents
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: https://www.excelforum.com/excel-pr...nd-output-results-on-3rd-sheet-using-vba.html
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,215,212
Messages
6,123,655
Members
449,113
Latest member
Hochanz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top