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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Have you tried recording a macro and seeing what comes out?
 
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,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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