View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Copy contents only

This doesn't work:
..Range(i, "a2:m2")

Are you trying to copy A2:M10000 to A7:M10006?

If yes, then just do it all at once:

Worksheets("Invoice").Range("a2:m10000").Copy
worksheets("master").range("a7").pastespecial paste:=xlpastevalues

Excel is smart enough to resize the destination range to match the copied range.

or

Dim RngToCopy as range
dim DestCell as range
set rngtocopy = worksheets("invoice").range("a2:m10000")
set destcell = worksheets("master").range("a7")

with rngtocopy
destcell.resize(.rows.count,.columns.count).value _
= .value
end with


Metrazal wrote:

I adjusted the code to allow multiple fields. However, I have an error.
Wheres my problem?

For i = 1 To 9999
Worksheets("Invoice").Range(i, "a2:m2").Copy
Worksheets("master").Range(i, "a7:m7").PasteSpecial
Paste:=xlPasteValues
Next i

Thanks,

Met

--
Metrazal
------------------------------------------------------------------------
Metrazal's Profile: http://www.excelforum.com/member.php...o&userid=31648
View this thread: http://www.excelforum.com/showthread...hreadid=518444


--

Dave Peterson