PDA

View Full Version : [SOLVED] range copy with paste



jwise
02-21-2014, 04:31 PM
OK, I admit I read somewhere to avoid copy/paste. I want to copy a row of data from one worksheet to another. First I copy the header row. But it copies only the data and I want things like column width copied as well. I can't seem to find the correct parameter to use to make it copy everything.

wsNewM.rows(1) = wsOldM.rows(1)

This was my first attempt and it moved nothing. So I added the ".Value" as such:

wsNewM.rows(1).Value = wsOldM.rows(1).Value

This copies the data but nothing else. (wsNewM and wsOldM are both worksheets and properly declared.)

I also notice that VBE religiously changes my capitalization of "Rows" to "rows". Why? I thought this was some kind of object readability issue.

Thanks

patel
02-21-2014, 11:18 PM
Sub a()
wsOldM.Rows(1).Copy wsNewM.Rows(1)
End Sub

jwise
02-22-2014, 12:48 AM
Thank you Patel. The code does indeed perform as expected.

I'm curious because I thought this used the clipboard (because of ".Copy"). Does this construction avoid the clipboard? Does this mean that the clipboard is used only when the "Paste" or "PasteSpecial" is used?

Thanks again.

patel
02-22-2014, 01:05 AM
I think my code uses the clipboard for copying, but erases it after execution.
You can have the same result with

Sub a()
wsOldM.Rows(1).Copy
wsNewM.Rows(1) .paste
Application.CutCopyMode = False
End Sub

jwise
02-22-2014, 10:59 PM
Thanks again. I'm definitely trying to avoid using the clipboard.