VBA Code for Copy/Paste

katk

Board Regular
Joined
Jul 21, 2009
Messages
62
All right, my last attempt to get help on this topic:

I have a code for copy/pasting a picture from one sheet to another:

Code:
Sub Picsy()
Sheets("Rough Draft").Shapes.Range(Array("Picture 2")).Select
    Selection.Copy
    Sheets("Final Copy").Select
    Range("D1").Select
    ActiveSheet.Paste
End Sub

If I select the picture (which is in fact named Picture 2) MANUALLY and then run the macro, it works. However, if anything else is selected when it starts to run, it copy/pastes that instead. This is bad A) because it should be selecting the picture per the first line of code and B) it's part of a much longer macro and it will take a lot more time if I have to break the macro up and manually select the picture in the middle. Can anyone help me figure out how to make it so it's *actually* selecting the picture before doing everything else?

Thanks!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Does this work?

Code:
Sub Picsy()
Sheets("Rough Draft").Shapes("Picture 2").Copy
Sheets("Final Copy").Range("D1").Paste
End Sub
 
Upvote 0
Paste is not a method for a Range object. Try this:

Code:
Sub Picsy()
Sheets("Rough Draft").Shapes("Picture 2").Copy
Sheets("Final Copy").Range("D1").PasteSpecial
End Sub
 
Upvote 0
Thanks for responding!

I tried the new coding in its own module and it worked fine. However, when I tried to insert it into my larger macro (at the very end, just to see if it would work), it said "PasteSpecial for this range class failed" (or something similar to that...). Any ideas on why?

For reference, the larger macro is mostly formatting and copy/pasting, with no complex statements:

Code:
Sub Finish2()
'(There's a lot more at the beginning, but it's just changing fonts, etc.)
' Final copy/paste
    Cells.Select
    Selection.Copy
    Sheets("Rough Draft").Select
    Sheets.Add
    ActiveSheet.Name = "Final Copy"
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    'Row height
    Sheets("Final Copy").Range("A13:L900").Select
    With Selection
    Selection.RowHeight = 23
    End With
    'Picture transfer
    Sheets("Rough Draft").Shapes("Picture 2").Copy
    Sheets("Final Copy").Range("D1").PasteSpecial
End Sub
 
Upvote 0
Working here

Code:
Sub Picsy()
Sheets("Rough Draft").Shapes("Picture 2").Copy
Sheets("Final Copy").PasteSpecial Format:="Microsoft Office Drawing Object"
With Sheets("Final Copy").Pictures(Sheets("Final Copy").Pictures.Count)
    .Top = Sheets("Final Copy").Range("D1").Top
    .Left = Sheets("Final Copy").Range("D1").Left
End With
End Sub
 
Upvote 0
Hmm, I'm still able to get the code running on its own, but not able to fit it into the larger code (now it's saying "PasteSpecial method of worksheet class failed." I tried a few modifications to no avail...

Would it be possible for me to keep the code you wrote in its own module and then "call" it from my larger code? I'm not sure how calling works, exactly...

Thanks again -- Katherine
 
Upvote 0
Update: I messed around with it a bit and was able to call your macro successfully into my larger one. Hooray! Thanks for all your help.
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,253
Members
452,900
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top