Transferring Data Between Worksheets

mharper90

Board Regular
Joined
May 28, 2013
Messages
117
Office Version
  1. 365
Platform
  1. MacOS
I'm trying to compare columns of first and last names (A:B) on ws1 with columns (A:B) on ws2. If the name exists on ws2, then I need to copy the value of ws1 columns (I:L) to ws2 columns (D:G) for the matching row.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi,
Try this.

Code:
Sub copydata()
Dim ws1 as worksheet
Dim ws2 as worksheet
Dim lr1&, lr2&
Dim c as range, c2 as range

Set ws1=sheets("Sheet1")
Set ws2=sheets("Sheets2")
lr1=ws1.range(rows.count,"a").end(xlup).row
lr2=ws2.range(rows.count,"a").end(xlup).row
For each c in ws1.range(range("A1"),range("A1").offset(lr1-1,0))
    For each c2 in ws2.range(range("A1"),range("A1").offset(lr2-1,0))
         If c.value & c.offset(0,1).value = c2.value & c2.offset(0,1).value then
            ws1.range(c.offset(0,8),c.offset(0,11)).copy ws2.range(c2.offset(0,3),c2.offset(0,6))
         Exit for
         end if
    Next c2
Next c

Set ws1=nothing
Set ws2=nothing
End sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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