VBA to copy one row at a time

ScottishTornado

New Member
Joined
Aug 2, 2016
Messages
5
Hello,

I have a workbook that requires me to copy data from one sheet to another.

The data I am copying is lifted from the original main page for analysis and possible amendments. I have been racking my brain over how to return this data if there has been any changes.

My thought is that I could use a loop to copy one row at a time back to the main sheet (which is filtered) one at a time, this would preserve any data.

Could anyone point me in the right direction?

thanks
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Is there a data point that uniquely identifies your data? If so, you could us this to link the child data back to the parent data.

Also, we need a little more details to help you. Are these copy activities happening via macro, or manually? At what point does "return this data" happen?
 
Upvote 0
Is there a data point that uniquely identifies your data? If so, you could us this to link the child data back to the parent data.

Also, we need a little more details to help you. Are these copy activities happening via macro, or manually? At what point does "return this data" happen?

Hey,

I have added a column that gives each row a unique number. The data is to be copied back when a button is clicked.

Is there any more details you need?
 
Upvote 0
Try this:

Code:
Sub CopyBackToMaster()


Dim FoundCell As Range
Dim MasterSht As String
Dim UpdatedSht As String
Dim MySearchString As Variant
Dim LastRow As Integer
Dim StartRow As Integer
Dim MyRow As Integer
Dim InRange As String
Dim OutRange As String




MasterSht = "Master" 'your name here
UpdatedSht = "Child" 'your name here


'assume column A has the unique key
LastRow = ThisWorkbook.Worksheets(UpdatedSht).Cells(Rows.Count, "A").End(xlUp).Row
StartRow = 2 'your first row of actual data


For MyRow = StartRow To LastRow


    'assume column A has the unique key
    MySearchString = ThisWorkbook.Worksheets(UpdatedSht).Cells(MyRow, 1)


    'assume the key is located in column A
    Set FoundCell = ThisWorkbook.Worksheets(MasterSht).Range("A:A").Find(MySearchString, LookIn:=xlValues)
    If Not FoundCell Is Nothing Then
        'copy back the data here
        InRange = MyRow & ":" & MyRow
        OutRange = FoundCell.Row & ":" & FoundCell.Row
        ThisWorkbook.Worksheets(UpdatedSht).Range(InRange).Copy
        ThisWorkbook.Worksheets(MasterSht).Range(OutRange).PasteSpecial Paste:=xlPasteValues
    End If
Next


Application.CutCopyMode = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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