Compare 2 columns against a 3rd column & copy those values

muejl1

New Member
Joined
Sep 8, 2016
Messages
6
I'm not even sure where to start...this is what I'm trying to accomplish:

1. I have Worksheet 1 that has ID numbers in column A
2. I have Worksheet 2 that also has ID numbers in column A...this worksheet will have some case sensitive duplicates
3. Column B on Worksheet 1 is blank
4. Column B on Worksheet 2 is filled with ID's.......

What I need to do is find the case sensitive matches for column A between Worksheet 1 and 2.......and if there's a value in column B on Worksheet 2, take it from Worksheet 1 (ID# from column B) and place it next to the exact match on Worksheet 2, in column B.

Example with desired results:

Worksheet 1
[TABLE="width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001j0Llj[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001j0N1J[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001jla29[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001jlA29
[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001j26mi[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Worksheet 2
[TABLE="width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]00TF000001j0Llj[/TD]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001jRrzK[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001j0N1J[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001jRGRO[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001jla29[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001jlJ9F[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001jkbfo[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001jkVRe[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[TD]

<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>
<!--StartFragment--> [TD="width: 65"]00TF000001jkV7f[/TD]
<!--EndFragment-->
</tbody>
[/TD]
[/TR]
[TR]
[TD]00TF000001jlA29
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001j0n1J
[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001jkCqG[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001jkBFy[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]00TF000001j26mi[/TD]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001jRrzK[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]


Desired Outcome
[TABLE="width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]00TF000001j0Llj[/TD]
[TD]00TF000001jRrzK[/TD]
[/TR]
[TR]
[TD]00TF000001j0N1J[/TD]
[TD]00TF000001jRGRO[/TD]
[/TR]
[TR]
[TD]00TF000001jla29[/TD]
[TD][TABLE="width: 65"]
<colgroup><col width="65" style="width:65pt"> </colgroup><tbody>[TR]
<!--StartFragment--> [TD="width: 65"]00TF000001jlJ9F[/TD]
<!--EndFragment--> [/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]00TF000001jlA29[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]00TF000001j26mi[/TD]
[TD]00TF000001jRrzK[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I'm sorry for the poor formatting...doesn't look like you can edit posts though. Thanks to anyone that can help me!
Erik
 
Upvote 0
Hi,

Maybe the below will help you? Enter formula with Ctrl+Shift+Enter, not just enter.

Excel Workbook
AB
100TF000001j0Llj00TF000001jRrzK
200TF000001j0N1J00TF000001jRGRO
300TF000001jla2900TF000001jlJ9F
400TF000001jlA290
500TF000001j26mi00TF000001jRrzK
Sheet 1


Excel Workbook
AB
100TF000001j0Llj00TF000001jRrzK
200TF000001j0N1J00TF000001jRGRO
300TF000001jla2900TF000001jlJ9F
400TF000001jkbfo*
500TF000001jkVRe00TF000001jkV7f
600TF000001jlA29*
700TF000001j0n1J*
800TF000001jkCqG00TF000001jkBFy
900TF000001j26mi00TF000001jRrzK
Sheet 2
 
Last edited:
Upvote 0
Hi Erik,

Try this:

Code:
Option Explicit
Sub Macro1()

    Dim lngMyRow      As Long
    Dim lngLastRow    As Long
    Dim lngPasteRow   As Long
    Dim rngFoundCell  As Range
    
    Application.ScreenUpdating = False
    
    lngLastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
    
    For lngMyRow = 2 To lngLastRow 'Assumes the data on 'Sheet1' starts at Row 2. Change to suit if necessary.
                
        Set rngFoundCell = Sheets("Sheet2").Columns("A").Find(What:=Sheets("Sheet1").Range("A" & lngMyRow), LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=False)
            
        If Not rngFoundCell Is Nothing Then
            On Error Resume Next
                lngPasteRow = Sheets("Sheet3").Range("A:B").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
                If lngPasteRow = 0 Then lngPasteRow = 2 'Initial output row on 'Sheet3' will be 2. Change to suit if necessary.
                Sheets("Sheet2").Range("A" & rngFoundCell.Row & ":B" & rngFoundCell.Row).Copy Destination:=Sheets("Sheet3").Range("A" & lngPasteRow)
            On Error GoTo 0
        End If
        
        Set rngFoundCell = Nothing 'Initialise varaible
        
    Next lngMyRow
    
    Application.ScreenUpdating = True
    
    MsgBox "Done"

End Sub

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,223,715
Messages
6,174,065
Members
452,542
Latest member
Bricklin

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