VBA PasteSpecial Format & Values

pbt

Well-known Member
Joined
Oct 18, 2005
Messages
1,613
I am trying to copy a range from one sheet and paste in another sheet via VBA.

This is the code I have:
Code:
Sheets("RECAP CURRENT YEAR").Select
     Range("E:E").Copy
     Sheets("FORECAST").Activate
     ActiveSheet.Paste Destination:=Range("IV1").End(xlToLeft).Offset(0, 1)
     Range("A1").Select

Column E has formulas (=SumB3:D3) nothing more then that. I get a #REF after the paste into the FORCAST sheet.

I would like to Paste Values and Formats.

I tried changing the code to this, with different variations:
Code:
Sheets("RECAP CURRENT YEAR").Select
     Range("E:E").Copy
     Sheets("FORECAST").Activate
     ActiveSheet.PasteSpecial Paste:=xlPasteFormats, xlPasteValues _
     Destination:=Range("IV1").End(xlToLeft).Offset(0, 1)
     Range("A1").Select
But keep comming up with errors.

Any ideas, Thanks
h.h.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Sheets("RECAP CURRENT YEAR").Select
Range("E:E").Copy
Sheets("FORECAST").Activate
ActiveSheet.Paste
Destination:=Range("IV1").End(xlToLeft).Offset(0, 1)
Range("A1").Selec

try this modification

Code:
Sheets("RECAP CURRENT YEAR").Select
     Range("E:E").Copy
     Sheets("FORECAST").Activate
set Destination:=Range("IV1").End(xlToLeft).Offset(0, 1)
Destination.PasteSpecial xlValues
range("a1").select
application.cutcopymode=false
 
Upvote 0
Thanks for the reply venkat

I get a syntax errorwith this line highlighted:
Code:
set Destination:=Range("IV1").End(xlToLeft).Offset(0, 1)

Also I need to paste Values and Formats
h.h.
 
Upvote 0
Hi hh
don't "Select/Activate"
Code:
Sheets("RECAP CURRENT YEAR").Range("E:E").Copy
With Sheets("FORECAST").Range("iv1").End(xlToLeft).Offset(,1)
     .PasteSpecial xlPasteFormats
     .PasteSpecial xlPasteValues
End With
 
Upvote 0
One more question, jindon

don't "Select/Activate"

Does this line actually "Activate" that sheet?
Code:
Sheets("RECAP CURRENT YEAR").Range("E:E").Copy

Or do you have to put in:
Code:
Sheets("RECAP CURRENT YEAR").Activate
Which I did not do. Just a learning question

Harry
 
Upvote 0
OK

Select/Activate creates errors unless properly written.

In most cases, you don't need to Select/Activate the object, if you specify the sheet

such like:

Regardless of the activesheet, you can do

Sheets("Sheet1").Columns("e").Delete
Sheets("Sheet2").Columns("a:f").Delete

Sheets("Sheet1").Range("a1").Value = Sheets("Sheet2").Range("c1").Value

Sheets("Sheet1").Range("a1").Copy Destination:= Sheets("Sheet2").Range("d1")

You don't need to select sheets/range and these action makes the code slower.
 
Upvote 0
Thanks for the explanation. :biggrin:

I will try to remember this in the future. Learn something every day :biggrin: :wink:

Harry
 
Upvote 0
The code was working Saturday night, but now it does't.

This is what I have:
Code:
Sub Forecast()
Dim ws As Worksheet
   Application.ScreenUpdating = False
   Sheets("RECAP CURRENT YEAR").Range("A:A").Copy
   With Sheets("FORECAST").Range("A:A")
     .PasteSpecial xlPasteFormats
     .PasteSpecial xlPasteValues
     .Columns("A:A").EntireColumn.AutoFit
End With
    Application.CutCopyMode = False
    
Sheets("RECAP CURRENT YEAR").Range("E:E").Copy
With Sheets("FORECAST").Range("iv1").End(xlToLeft).Offset(, 1)
     .PasteSpecial xlPasteFormats
     .PasteSpecial xlPasteValues
End With
     Range("A1").Select
     Application.CutCopyMode = False
     Application.ScreenUpdating = True
End Sub

Stepping through the code, it does the first half then copies Range ("E:E")
But from there nothing happens. I have no errors, and continueing with (F8) key, it will step through to the End.

Anybody have an idea.

h.h.
 
Upvote 0
Disregard the above problem.

:oops: I solved it :oops:

Somehow I had something in column IU & IV :rolleyes:

Cleared it out ~ works fine now.

h.h.
I need somewhere to hide for awhile
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,509
Members
449,089
Latest member
RandomExceller01

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