I need someto gove me a good idea ofthe best way to do a copy paste between workbooks. I have been doine it as follows:
Sub FACSub1()
'
' FACSub1 Macro
' Macro recorded 7/22/2011 by lvannorman
'
'
ActiveSheet.Range("N2:Y2").Select
Selection.Copy
ChDir "\\SERVER\Shared\Operation Production\z Reports"
Workbooks.Open Filename:= _
"\\SERVER\Shared\Operation Production\z Reports\FAC Sub-Assembly Batch Summary.xls"
Sheets("Summary information").Select
Range("A2").Select
While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Wend
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub
But I have been told that I should place the selection copy command after the "wend" and not at the beginning.
All suggestions + comments welcome.
Thanks
Please read the forum rules regarding code tags - all code you post must be enclosed in code tags - see the rules here.
You need to loop through the range and paste the values into the next blank cells
Hope this helps.Sub FACSub1() ActiveSheet.Range("N2:Y2").Copy ChDir "\\SERVER\Shared\Operation Production\z Reports" Workbooks.Open Filename:= _ "\\SERVER\Shared\Operation Production\z Reports\FAC Sub-Assembly Batch Summary.xls" Sheets("Summary information").Range("A2").Select While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select Wend Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False ActiveWorkbook.Close True ' this will save and close the workbook in one statement End Sub
Anthony
“Confidence never comes from having all the answers; it comes from being open to all the questions.”
PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”
Last edited by smuzoen; 02-03-2012 at 05:31 PM. Reason: Fix code
The wend is the end of the loop in the previous post and the paste command needs to be here as you loop through cells until you find the next cell that is empty.But I have been told that I should place the selection copy command after the "wend" and not at the beginning.
See edited code - misunderstood - sorry. If you want to paste the values into the last free row in Column A then you could use
Hope this helps.Sub FACSub1() ActiveSheet.Range("N2:Y2").Copy ChDir "\\SERVER\Shared\Operation Production\z Reports" Workbooks.Open Filename:= _ "\\SERVER\Shared\Operation Production\z Reports\FAC Sub-Assembly Batch Summary.xls" Sheets("Summary information").Range("A" & Cells(Rows.Count, "A").End(xlUp).Row + 1).PasteSpecial _ Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False ActiveWorkbook.Close True End Sub
Anthony
“Confidence never comes from having all the answers; it comes from being open to all the questions.”
PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”
Last edited by smuzoen; 02-03-2012 at 05:45 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks