Compare 2 columns between sheets

mrsriexcel

New Member
Joined
Sep 30, 2015
Messages
15
Hi,
I have two sheets named Sheet1,Sheet2.
If ColumnA and ColumnC in Sheet1 is exactly matching with ColumnA and ColumnC in Sheet2, copy the entire matching record (A1 to Z1) in sheet2 to sheet3.

Please help me with Excel formula/VBA code for this scenario.

Regards,
Sri
 
In your Original post you wanted to check Columns A & C, your now saying columns A & B.
Try this
Code:
Sub CheckMove()

    Dim Dict As Object
    Dim Rng As Range
    Dim UsdRws1 As Long
    Dim UsdRws2 As Long
    Dim Chk As String

    UsdRws1 = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
    UsdRws2 = Sheet2.Range("A" & Rows.Count).End(xlUp).Row
    Set Dict = CreateObject("scripting.dictionary")
    
    For Each Rng In Sheet2.Range("A2:A" & UsdRws2)
        Dict(Rng.Text & "|" & Rng.Offset(, 1).Text) = Rng.Row
    Next Rng

    For Each Rng In Sheet1.Range("A2:A" & UsdRws1)
    Chk = (Rng.Text & "|" & Rng.Offset(, 1).Text)
        If Dict.exists(Chk) Then
            Sheet2.Rows(Dict.Item(Chk)).Copy _
                Sheet3.Range("A" & Rows.Count).End(xlUp).Offset(1)
        End If
    Next Rng
End Sub
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Take the combination of Column A and B in Sheet 1 and check/search in Sheet2. The outcome of this search/records/Columns should copied over to Sheet3.

mrsriexcel,

1. So, we are now checking columns A, and, B, instead of columns A, and, C?

2. And, there are titles in row 1 of each worksheet?

3. And, we are copying the rows from column A, thru, column Z?
 
Last edited:
Upvote 0
mrsriexcel,

With the same titles in row 1, in worksheets Sheet1, Sheet2, and, Sheet3, and, we are now checking columns A, and, B, then try the following macro:


Code:
Sub mrsriexcel()
' hiker95, 08/07/2017, ME1017679
Dim w1 As Worksheet, w2 As Worksheet, w3 As Worksheet
Dim r As Range, a As Range, nr As Long
Set w1 = Sheets("Sheet1")
Set w2 = Sheets("Sheet2")
Set w3 = Sheets("Sheet3")
With w2
  For Each r In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
    Set a = w1.Columns(1).Find(r.Value, LookAt:=xlWhole)
    If Not a Is Nothing Then
      If r.Offset(, 1).Value = a.Offset(, 1).Value Then
        nr = w3.Cells(w3.Rows.Count, "A").End(xlUp).Row + 1
        w3.Cells(nr, 1).Resize(, 26).Value = w2.Cells(r.Row, 1).Resize(, 26).Value
        w3.Cells(nr, 2).NumberFormat = "mm-dd"
      End If
    End If
  Next r
End With
With w3
  .Activate
  .Columns(1).Resize(, 26).AutoFit
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,214
Members
453,024
Latest member
Wingit77

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