Macro for copying and replacing data [Closed]

Report
-
Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
-
Hello,

I'm looking for the best way, which I am assuming is a macro to copy data from one spredsheet to another. The macro must copy all data from one spreadsheet (sheet2) row by row to another spreadsheet (sheet1). It must copy based on a value in column A in sheet 2 then look for the same value in column A sheet 1 and replace it with the copied row (the whole row must be copied and replaced)

appreciate any help


1 reply

Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
797
not clear

"replace it with the copied row "

sheet1 is to be replaced by sheet 2 or sheet 2 is to be replaced by sheet1????

try this macro and modify if necessary

Sub test()
Dim r As Range, c As Range, r1 As Range, x As String
With Worksheets("sheet1")
Set r = Range(.Range("A2"), .Range("A2").End(xlDown))
For Each c In r
x = c.Value
With Worksheets("sheet2").Columns("A:A")
Set r1 = .Cells.Find(what:=x, lookat:=xlWhole)
If Not r1 Is Nothing Then
r1.EntireRow.Copy
End If
End With
c.PasteSpecial
Next c
End With


End Sub

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!