pasting formats with vba

G

Guest

Guest
When I copy a worksheet and then paste it to another, some formatting doesn't follow. ex. column width etc. What code do I use to make the column width paste too. Used this code to copy.

Worksheets("template").UsedRange.SpecialCells(xlCellTypeVisible).Copy
Worksheets(2).Activate
Range("A1").Select
ActiveSheet.Paste
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
It's a separate procedure, add the code to the end of your current procedure. May make your workbook big:

application.screenupdating = false
Worksheets("template").Cells.Select
Selection.Copy
[a1].select
Worksheets(2).Activate
Cells.Select
Selection.PasteSpecial Paste:=xlFormats
[a1].select
application.screenupdating = true

Cheers, Nate
This message was edited by NateO on 2002-03-12 16:23
 
Upvote 0
To paste the column widths use this

Const xlColumnWidths = 8

Selection.PasteSpecial Paste:=xlColumnWidths

OR

Selection.PasteSpecial Paste:=8


Ivan
 
Upvote 0
On 2002-03-12 18:32, Ivan F Moala wrote:
To paste the column widths use this

Const xlColumnWidths = 8

Selection.PasteSpecial Paste:=xlColumnWidths

OR

Selection.PasteSpecial Paste:=8


Ivan

I should have explained further.
The pastespecial xlcoulmnwidths does not
work properly in excel2000.
Try it and see ie record a macro using the
pastespecial columnwidths.
Then run it.....you will receive and error.
The code I gave is a work around to this problem.


Ivan
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,287
Members
448,562
Latest member
Flashbond

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