Copying and pasting using VBA when not on that sheet

Dscalf1

New Member
Joined
Jun 14, 2015
Messages
41
I am trying to copy and paste information on another sheet that isnt the active sheet. Here is my code It is giving me the error on the first line and im not sure why.

Code:
Sub Copy_Paste()


    Sheets("Dough Information").Range("H3:J152").Select
    Selection.Copy
    Sheets("Dough Information").Range("K3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
You cannot select a range on a sheet if that is not the active sheet at the time.
However, you don't need to select it at all. Most "Select" statements can be eliminated, i.e.
combine these two rows:
Code:
    Sheets("Dough Information").Range("H3:J152").Select
    Selection.Copy
to just this:
Code:
    Sheets("Dough Information").Range("H3:J152").Copy
(you don't need to actually select a range first before copying it in VBA).
 
Last edited:
Upvote 0
Try:
Code:
Sub Copy_Paste()
    With Sheets("Dough Information")
        .Range("H3:J152").Copy
        .Range("K3").PasteSpecial Paste:=xlPasteValues
    End With
    Application.CutCopyMode = False
End Sub
 
Upvote 0
Thank yall for all the information I did not know that!! mumps that code worked great! Thank You!
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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