DougStroud
Well-known Member
- Joined
- Aug 16, 2005
- Messages
- 2,968
This should be a simple 1,2,3 operation, but one I am struggling to find the answers for.
It may be trivial I realize..... I searched the help file, the board and nothing really explains the parameters.
I wanted to copy a range of data and paste it in another range. But I was unable, so I used the MacroRecorder to see what I might be doing wrong.
This was not immediately apparent to me, but after much work I located a starting point.
1. To paste from one cell to another requires PasteSpecial, not just Paste.
This was not apparent to me. It was not until I accidentally hit the autofill and in VBA and it filled it in, (I did not catch this until later that it was PasteSpecial rather than Paste). And Paste is not an option here.
2. The MacroRecorder gets away w/ it by using just Paste if it uses ActiveSheet.
3. if I fully qualify where I want the data to paste, not using the ActiveSheet object, again it fails, why?
What are the rules governing for writing single line or double line code, ie, copy/paste if you specify destination can be done in one line, if the destination is omitted then this becomes a double line piece of code but PasteSpecial is required and if the use of Activesheet eliminates PasteSpecial and Paste can be used.
Very confusing.
Is there a published set of rules regarding things of this nature?
I would appreciate any help or ideas here to find answers to the above questions, as they are important to fully grasping the programming rules here.
Here are four versions, the third fails if anyone is able to comment.
This one Fails
Thanks,
Doug
It may be trivial I realize..... I searched the help file, the board and nothing really explains the parameters.
I wanted to copy a range of data and paste it in another range. But I was unable, so I used the MacroRecorder to see what I might be doing wrong.
This was not immediately apparent to me, but after much work I located a starting point.
1. To paste from one cell to another requires PasteSpecial, not just Paste.
This was not apparent to me. It was not until I accidentally hit the autofill and in VBA and it filled it in, (I did not catch this until later that it was PasteSpecial rather than Paste). And Paste is not an option here.
2. The MacroRecorder gets away w/ it by using just Paste if it uses ActiveSheet.
3. if I fully qualify where I want the data to paste, not using the ActiveSheet object, again it fails, why?
What are the rules governing for writing single line or double line code, ie, copy/paste if you specify destination can be done in one line, if the destination is omitted then this becomes a double line piece of code but PasteSpecial is required and if the use of Activesheet eliminates PasteSpecial and Paste can be used.
Very confusing.
Is there a published set of rules regarding things of this nature?
I would appreciate any help or ideas here to find answers to the above questions, as they are important to fully grasping the programming rules here.
Here are four versions, the third fails if anyone is able to comment.
Code:
Sub Macro3()
Range("A3:G15").Select
Application.CutCopyMode = False
Selection.Copy
Range("O3").Select
ActiveSheet.Paste
End Sub
Code:
Sub whatthehe()
ActiveSheet.UsedRange.Copy
Range("O18").PasteSpecial
End Sub
This one Fails
Code:
Sub whattheheck()
ActiveSheet.Range("A3").Copy
Range("O1").Paste
End Sub
Code:
Sub whattheheck2()
ActiveSheet.Range("A3:D3").Copy Destination:=Range("w3")
End Sub
Doug