VBA - Script to search and replace values in rows between sheets based on criteria

RobertHamberg

New Member
Joined
Jan 11, 2018
Messages
34
Office Version
  1. 365
I want ascript to search for the values in column A in sheet 1 and try to find a match in column A in Sheet 2. If a match is found I want the script to copy the values in column F-J in sheet 1 and add those values to column F-J in sheet 2 on the matching rows. Anyone able to help? :)

Sheet 1
ABCDEFGHIJ
1NameOwnerStartEndTime (H)TeamR1%R2%
2Test2Owner22018-01-012018-12-31200Team2Resurs210000
3Test3Owner32018-01-012018-12-31300Team3Resurs310000
4Test5Owner52018-01-012018-12-31500Team5Resurs510000
5Test6Owner62018-01-012018-12-31600Team6Resurs675Resurs325
6Test8Owner82018-01-012018-12-31800Team8Resurs850Resurs750
7Test10Owner102018-01-012018-12-311 000Team10Resurs1050Resurs950

<tbody>
</tbody>

<tbody>
</tbody>
Sheet 2
ABCDEFGHIJ
1NameOwnerStartEndTime (H)TeamR1%R2%
2Test1Owner12018-01-012018-12-31100
3Test2Owner22018-01-012018-12-31200
4Test3Owner32018-01-012018-12-31300
5Test4Owner42018-01-012018-12-31400
6Test5Owner52018-01-012018-12-31500
7Test6Owner62018-01-012018-12-31600
8Test7Owner72018-01-012018-12-31700
9Test8Owner82018-01-012018-12-31800
10Test9Owner92018-01-012018-12-31900
11Test10Owner102018-01-012018-12-311 000

<tbody>
</tbody>

<tbody>
</tbody>
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Untested, but try this
Code:
Sub CopyCols()

   Dim Cl As Range
   Dim Sht1 As Worksheet
   Dim Sht2 As Worksheet
   
   Set Sht1 = Sheets("Sheet1")
   Set Sht2 = Sheets("Sheet2")
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Sht1.Range("A2", Sht1.Range("A" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then .Add Cl.Value, Cl
      Next Cl
      For Each Cl In Sht2.Range("A2", Sht2.Range("A" & Rows.Count).End(xlUp))
         If .exists(Cl.Value) Then .Item(Cl.Value).EntireRow.Copy Cl
      Next Cl
   End With

End Sub
 
Upvote 0
Works like a charm, so thankfull for all the help you've provided!

Untested, but try this
Code:
Sub CopyCols()

   Dim Cl As Range
   Dim Sht1 As Worksheet
   Dim Sht2 As Worksheet
   
   Set Sht1 = Sheets("Sheet1")
   Set Sht2 = Sheets("Sheet2")
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Sht1.Range("A2", Sht1.Range("A" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then .Add Cl.Value, Cl
      Next Cl
      For Each Cl In Sht2.Range("A2", Sht2.Range("A" & Rows.Count).End(xlUp))
         If .exists(Cl.Value) Then .Item(Cl.Value).EntireRow.Copy Cl
      Next Cl
   End With

End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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