vba copy paste values and formats

jtodd

Board Regular
Joined
Aug 4, 2014
Messages
194
Hi
What i need to do is copy and past data from one sheet to another .
The issue is that i want to copy the values and formats but not the formulas. I have the folowing code

Sub CopyWeekly()
Sheets("WeeklyDetail").Unprotect Password:="xxxx"
Range("a1:g40").Copy

Sheets("WeeklyDetail").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues

Sheets("WeeklyDetail").Protect Password:="xxxxx"

End Sub
This works fine but how do I copy formats as well . I have tried
Sub CopyWeekly()
Sheets("WeeklyDetail").Unprotect Password:="xxxxxx"
Range("a1:g40").Copy

Sheets("WeeklyDetail").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormats
Sheets("WeeklyDetail").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues

Sheets("WeeklyDetail").Protect Password:="xxxxx"


End Sub

But just get error message

Can anybody help
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Have you tried recording a macro and seeing what comes out?
 
Upvote 0
I think it's because part of your Paste range is inside the copy range.
 
Upvote 0
Try
Code:
Sub CopyWeekly()
   Sheets("WeeklyDetail").Unprotect Password:="xxxxxx"
   Sheets("[COLOR=#ff0000]New[/COLOR]").Range("a1:g40").Copy
   With Sheets("WeeklyDetail").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
      .PasteSpecial xlPasteValues
      .PasteSpecial xlPasteFormats
   End With
   
   Sheets("WeeklyDetail").Protect Password:="xxxxx"

End Sub
Where the value in red is the sheet name you are copying from.
If this doesn't work, what error do you get & what line is highlighted?
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,976
Members
448,934
Latest member
audette89

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