CluelessNobel
New Member
- Joined
- Oct 24, 2015
- Messages
- 24
Hi,
So I'm trying to create a macro that would basically copy+paste data from one workbook to an other.
Specifics:
Workbook 1 has say 5 rows and 5 columns
Workbook 2 has 1 row and 5 columns
The columns from each workbook aren't necessarily named the same, and don't come in the same order.
I need the macro to copy+paste the first row of workbook 1 (although column by column), in the right columns of workbook 2.
Once it's done with the first row, I need it to open a new workbook 2, go to the second row of workbook 1 and repeat the copy+pasting tasks until there are no rows containing data left.
Workbook 1:
<tbody>
</tbody>
Workbook 2 (target workbook):
<tbody>
</tbody>
I found this code:
Obviously there is no loop, and I most likely need variables (but I suck at this).
Thanks for taking the time to read this
So I'm trying to create a macro that would basically copy+paste data from one workbook to an other.
Specifics:
Workbook 1 has say 5 rows and 5 columns
Workbook 2 has 1 row and 5 columns
The columns from each workbook aren't necessarily named the same, and don't come in the same order.
I need the macro to copy+paste the first row of workbook 1 (although column by column), in the right columns of workbook 2.
Once it's done with the first row, I need it to open a new workbook 2, go to the second row of workbook 1 and repeat the copy+pasting tasks until there are no rows containing data left.
Workbook 1:
File Number | Name | # | $ | € |
1 | CR | 15 | 100 | 500 |
2 | DC | 20 | 200 | 1000 |
3 | RIO | 25 | 300 | 1500 |
4 | CM | 30 | 400 | 2000 |
5 | PU | 35 | 500 | 2500 |
<tbody>
</tbody>
Workbook 2 (target workbook):
Number | Data1 | Data 2 | Data 3 | Data 4 |
<tbody>
</tbody>
I found this code:
Code:
Sub A48()
Dim wb As Workbook
Dim ws As Worksheet
Set wb = Workbooks.Open("P:\CAC\Workbook2.xls")
'Name'
Windows("Workbook1.csv").Activate
Sheets("Workbook1").Select
Range("B2").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Workbook2.xls").Activate
Sheets("Workbook2").Select
Range("C2").Select
ActiveSheet.Paste
'Number'
Windows("Workbook1.csv").Activate
Sheets("Workbook1").Select
Range("A2").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Workbook2.xls").Activate
Sheets("Workbook2").Select
Range("A2").Select
ActiveSheet.Paste
End Sub
Obviously there is no loop, and I most likely need variables (but I suck at this).
Thanks for taking the time to read this