|
-
Mar 15th, 2005, 09:11 AM
#3
Thread Starter
Frenzied Member
Re: HOW TO: Paste to a different sheet PROGRAMATICALLY ???
Vince:
I get an error message at "rng.Paste":
"Object doesn't support this property or method"
However, "rng.Select" does not result in an error (but it doesn't paste either!).
Actually, I did get "ActiveSheet.Paste" to work last night ... after numerous guesses, I finally discovered that if I set the ENTIRE Paste range accurately, it works with variables. Thanks for your commented out suggestion "bsheet.Paste" ... it works great!
Code:
Option Explicit
Sub Macro1()
'
Dim asheet As Worksheet 'First Sheet in book
Dim bsheet As Worksheet 'Second Sheet in book
Dim rng As Range 'Misc Range variable
Dim cb As Integer 'Beginning Column
Dim ce As Integer 'Ending Column
Dim rb As Integer 'Beginning Row
Dim re As Integer 'Ending Row
Set asheet = Sheets("Sheet1")
Set bsheet = Sheets("Sheet2")
' Define the Source Area for the Copy/Paste
cb = 3 'left column of range
ce = 6 'right column of range
rb = 2 'top row of range
re = 3 'bottom row of range
' Copy the Source Area
Range(asheet.Cells(rb, cb), asheet.Cells(re, ce)).Copy
' Define the Target Area Cells
cb = cb + 2: ce = ce + 2
rb = rb + 3: re = re + 3
' Define the Target area Sheet and Cells
' To use variables, you MUST define the ENTIRE paste area!!
' ... not just the Top-Left cell as with explicit reference strings
Set rng = Range(bsheet.Cells(rb, cb), bsheet.Cells(re, ce))
'rng.Paste '<< This does NOT work
bsheet.Paste Destination:=rng 'This works!
End Sub
Thanks for your input ... if you get 'rng.Paste' to work somehow, I would still like to know about it, but I think it has to reference a sheet object instead of a range object.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|