Paste Special using Range in VBA

MarkVMcCullagh

Board Regular
Joined
Oct 22, 2002
Messages
72
How do I modify the following line within VBA to paste special values, formats and column widths?

WS.Range("d22:t42").Copy Destination:=Sheets("Consolidated").Range("A65536").End(xlUp).Offset(1, 0)

Thanks in Advance
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi Mark,

To paste special you must switch to the Copy and PasteSpecial methods separately. In addition, to paste values and formats (assuming you mean all cell formats and not just numberformats) you must paste values and formats separately. I believe this will do it:

Code:
WS.Range("d22:t42").Copy
With Sheets("Consolidated").Range("A65536").End(xlUp).Offset(1)
   .PasteSpecial xlPasteValues
   .PasteSpecial xlPasteFormats
End With

But regarding column widths, you can't do this with a range of cells (as in your example) that is not a complete column because column widths apply to entire columns only. If you want to set the column width of your destination columns to that of your source columns the following code could be used:

Code:
   For Each col In WS.Columns("D:T")
      Sheets("Consolidated").Columns(col.Column-3).ColumnWidth = col.ColumnWidth
   Next col

Damon
 
Upvote 0
You could also use Paste Special>Column Widths.

Adding to Damon's code.
Code:
WS.Range("d22:t42").Copy 
With Sheets("Consolidated").Range("A65536").End(xlUp).Offset(1) 
   .PasteSpecial xlPasteValues 
   .PasteSpecial xlPasteFormats 
   .PasteSpecial Paste:=xlColumnWidths
End With
Note I think this option is only available from Excel 2000 onwards.

Could be wrong though.:)
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,457
Members
449,083
Latest member
Ava19

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