Hi everyone,
I recently started learning VBA on my own. I would like to use VBA to automatically copy different outputs from one Excel file to another one. In the original data file, I have 10 outputs (let's say, A-J) with different sizes/ranges. I want to copy them into one single sheet in a destination file. In the destination file, each output will be pasted to the worksheet called "Final Data", according to the range that I assign.
'copy output A from original data
Workbooks("Original Data").Sheets("A").Activate
lastrow = Cells.Find(What:="*", SearchDirection:=xlPrevious).Row
lastcol = Cells.Find(What:="*", SearchDirection:=xlPrevious).Column
ActiveSheet.Range(Cells(2,1),Cells(lastrow,lastcol)).Copy
'paste output A to sheet "Final Data" in destination file
Workbooks("Destination Data").Sheets("Final Data").Activate
ActiveSheet.Range("B5").PasteSpecial xlPasteValues
I figured out the syntax for copy/paste 1 single output at a time. To improve efficiency, I want to use the loop to reference each of the 10 outputs, then paste them to their assigned range. Is there a way to dynamic change Sheets("A") to "B","C", etc., and also change Range("B5") to "B18" (for destination of output B), "B121" (for destination of output C), etc.? Thank you!
I recently started learning VBA on my own. I would like to use VBA to automatically copy different outputs from one Excel file to another one. In the original data file, I have 10 outputs (let's say, A-J) with different sizes/ranges. I want to copy them into one single sheet in a destination file. In the destination file, each output will be pasted to the worksheet called "Final Data", according to the range that I assign.
'copy output A from original data
Workbooks("Original Data").Sheets("A").Activate
lastrow = Cells.Find(What:="*", SearchDirection:=xlPrevious).Row
lastcol = Cells.Find(What:="*", SearchDirection:=xlPrevious).Column
ActiveSheet.Range(Cells(2,1),Cells(lastrow,lastcol)).Copy
'paste output A to sheet "Final Data" in destination file
Workbooks("Destination Data").Sheets("Final Data").Activate
ActiveSheet.Range("B5").PasteSpecial xlPasteValues
I figured out the syntax for copy/paste 1 single output at a time. To improve efficiency, I want to use the loop to reference each of the 10 outputs, then paste them to their assigned range. Is there a way to dynamic change Sheets("A") to "B","C", etc., and also change Range("B5") to "B18" (for destination of output B), "B121" (for destination of output C), etc.? Thank you!