Trying to paste values AND FORMATTING..

JohnZ1156

Board Regular
Joined
Apr 10, 2021
Messages
152
Office Version
  1. 2021
Platform
  1. Windows
I have a range of cells which contain numbers, text and dates. Using VBA, I have "copied" the range. Now I make my target cell the active cell and want to paste the values with the formatting to this different sheet. It is pasting the values but not duplicating the text formatting or alignment formats (centered).

I wouild like the macro to copy the text font, date formats, number formats and alignment formats (centered).

Here's my code:
VBA Code:
Sub testone()

    Worksheets("Invoice").Activate

    Range("D20").Select

    NumRows = Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row - ActiveCell.Row + 1
'    MsgBox (NumRows)

    Range("P20:W" & NumRows + 19).Select
    Selection.Copy

    Sheets("Invoice List").Select
    Range("A1").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Select

    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats

End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Two steps.

VBA Code:
    Selection.PasteSpecial Paste:=xlPasteValues
    Selection.PasteSpecial Paste:=xlPasteFormats
 
Upvote 0
Solution
Hi 6StringJazzer

Thank you. I didn't realize that it required 2 steps.
My logic told me that "Paste:=xlPasteValuesAndNumberFormats" should work.
I guess I was wrong again.

Thanks for your help.
John.
 
Upvote 0
NumberFormats is just for the number formats, that is, number of decimal points, whether it's a %, and so forth. You also need alignment and font formatting. PasteFormats includes all formatting.
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,962
Latest member
Fenes

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