VB Script To Identify Matching Values and Enter Associated Data

dimyona

New Member
Joined
Jul 3, 2014
Messages
1
I have two sheets. Sheet1 contains a list of SKUS(A) and associated UPC's(B). The other list contains just UPCs(B). I'm working on a script to identify the matching cells UPCS between both sheets, and copy the associated SKU from Sheet1 into matching cells in column A Sheet2.

I hope I'm making myself clear. Any ideas here?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
See if this will work. Copy the code to the standard code module 1.
Code:
Sub matchNcpy()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range, c As Range, fLoc As Range
Set sh1 = Sheets(1) 'Edit sheet name
Set sh2 = Sheets(2) 'Edit sheet name
lr = sh2.Cells(Rows.Count, 2).End(xlUp).Row
Set rng = sh2.Range("B2:B" & lr)
    For Each c In rng
        Set fLoc = sh1.Range("B:B").Find(c.Value, , xlValues)
            If Not fLoc Is Nothing Then
                fLoc.Offset(0, -1).Copy c.Offset(0, -1)
            End If
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,249
Members
449,075
Latest member
staticfluids

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