Wednesday, 15 August 2012

vba - How do I get a macro to run the same operation but with 2 seperate workbooks, not the same ones I used to record the macro? -


I hope this is a clear description of what I want to achieve.

I just had a copy and paste value and it was an operation for me. I was hoping that a macro could speed up a little process.

Basically I want to copy 48,6,8,10 ... 48 to column D in a specific workbook and paste the values ​​into 23,24,25 cells. 46 In the second workbook, in column J, in the next step in the first workbook, copy the values ​​of 3,579, 499 to column D and paste values ​​into only 23,24,25 cells. In the second, 46 workbooks in column X

Obviously I can copy and paste them, but I have thousands of these and a macro could help.

this can help:

  sub copy () less I long as long, as long as the workbook, wb1 as long as the workbook, as long as the column column wb2, column J as long column wb1 = workbooks ("Workbook 1 .xls ") Replace it with the actual name wb2 = replace the workbooks (" workspace 2.xls ") with the actual name columnD = range (" D1 "). Column J = Range ("J1"). Column column X = range ("X1"). I = 2 to 49 step 2 wb2.Sheets ("Sheet1") for column = k = 23. Cell (k, columnJ) = wb1.Sheets ("Sheet1"). Cell (i, column D) wb2.Sheets ("Sheet1"). Cell (k, columnX) = wb1.Sheets ("Sheet1"). Cell (i + 1, columnD) k = k + 1 Next I end sub   

This is what you have asked. But you have to change the names of the workbooks and eventually the names of the sheets have to be changed. I tested it with some random data and it worked.

No comments:

Post a Comment