Hi
I'm trying to write a code that will copy data from a specific column in one workbook and paste that data in another workbook that has a matching column heading. In this case I'm copying data from one column with the heading "dog" to another column with the heading "dog." I will not always know which columns contain which heading, so the code will have to search through using a loop. I'm starting with searching through the first 5 columns.
"Run-Time Error '1004': Application-defined or object defined error" appears when I try to run the following code:
Any help on this is greatly appreciated!
I'm trying to write a code that will copy data from a specific column in one workbook and paste that data in another workbook that has a matching column heading. In this case I'm copying data from one column with the heading "dog" to another column with the heading "dog." I will not always know which columns contain which heading, so the code will have to search through using a loop. I'm starting with searching through the first 5 columns.
"Run-Time Error '1004': Application-defined or object defined error" appears when I try to run the following code:
Code:
Sub ColMatch()
Dim i As Integer
For i = 1 To 5
If Workbooks("Source Data WB - Copy data to WB").Sheets("Source").Cells(1, i) = "Dog" Then
Workbooks("Source Data WB - Copy data to WB").Sheets("Source").Range(Cells(2, i), Cells(6, i)).Copy 'ERROR!!!!!
'Selection.Copy
End If
Next i
Dim j As Integer
For j = 1 To 5
If Workbooks("Target Data WB- Copy data to WB").Sheets("Target WB").Cells(1, j) = "Dog" Then
Workbooks("Target Data WB- Copy data to WB").Sheets("Target WB").Range(Cells(2, i), Cells(6, i)).Select
Workbooks("Target Data WB- Copy data to WB").Sheets("Target WB").Paste
End If
Next j
End Sub
Any help on this is greatly appreciated!