3
wbTarget.Sheets("Sheet1").Range("A1:W79").Value = wb.Sheets(wsSource.Name).Range("A1:W79").Value

I have this code which works pasting the values of wb.Sheets(wsSource.Name) to wbTarget sheets. However, it only pastes the value and not the format/color. How do I paste it including the fonts, color of cell.

2
  • 1
    Perhaps you could do what you want manually with the macro recorder turned on, and then look at the resulting code. Commented Mar 30, 2017 at 8:31
  • Do you want the equivalent of Ctrl-C - Ctrl-V - i.e. a full copy, or just the value, font and colour? Commented Mar 30, 2017 at 8:32

1 Answer 1

10

You need to use Copy, and PasteSpecial xlValues and PasteSpecial xlFormats.

' Copy
wb.Sheets(wsSource.Name).Range("A1:W79").Copy
' Paste Special
wbTarget.Sheets("Sheet1").Range("A1:W79").PasteSpecial xlValues
wbTarget.Sheets("Sheet1").Range("A1:W79").PasteSpecial xlFormats

Read about Range.PasteSpecial here MSDN

Sign up to request clarification or add additional context in comments.

3 Comments

Hi thanks for your help! Can I change the Range to be dynamic? So I hope to copy everything dynamically and not just A1:W79. How should I substitute it?
@Desmond what is changing ? number of rows ? columns ? both ?
Both can change. So if the sheet contains data in A1:W79, I would copy and paste that. If a sheet contains data in C3:F7, I would copy that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.