VBA To find match of cell value and copy adjacent cell when match found

CharlieRog

New Member
Joined
Sep 13, 2019
Messages
14
Looking for vba code to see if data from 2 different cells on 2 different sheets if it matches then it copies the cell to the right on sheet 2 and pastes it to the cell on the right on sheet 1.

All the data in sheet 1 column M is present on sheet 2 column A. So when it finds a match in column M (sheet 1) with the same value in column A (sheet 2) it copies value of adjacent cell in column B (sheet 2) and pastes it on sheet 1 in column N. And then moves onto the next until complete
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
In future you would be better off starting a new thread, rather than posting to an old one.
I only saw your post by chance.

How about
VBA Code:
Sub freerskys()
    Dim Cl As Range
    Dim Dic As Object
   
    Set Dic = CreateObject("scripting.dictionary")
    With Sheets("Sheet2")
        For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
            Dic(Cl.Value) = Array(Cl, Cl.Offset(, 1).Value)
        Next Cl
    End With
    With Sheets("Sheet1")
        For Each Cl In .Range("M2", .Range("M" & Rows.Count).End(xlUp))
            If Dic.Exists(Cl.Value) Then
               Cl.Offset(, 1).Value = Dic(Cl.Value)(1)
               Dic(Cl.Value)(0).Interior.Color = vbRed
            End If
        Next Cl
    End With
End Sub
Can this be modified to match a wildcard value on sheet1? Example: if Cl value on sheet 2 = 300 and Cl value on sheet 1 = D300
 
Upvote 0
Please start a thread of your own, for this question. Thanks
 
Upvote 0
Hi,
How do you reference another workbook in the code above instead of "Sheet1" to copy the data to?
Thanks.
 
Upvote 0
Hi & welcome to MrExcel.
Please star a new thread for your question as it is different from the Ops. Thanks
 
Upvote 0

Forum statistics

Threads
1,223,262
Messages
6,171,080
Members
452,377
Latest member
bradfordsam

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