0

While copying data from one Excel sheet to another workbook I have to paste data with the same format because each cell has interior color. I will also delete the data from the original sheet which I copied from. Is it possible to keep the source formatting?

Workbooks.Add
Set Outbook1 = ActiveWorkbook
OutBook.Activate
OutBook.Sheets("Sheet6").Select
Lines = ActiveSheet.Range("A65536").End(xlUp).Row
Range("A1:N" & Lines).Select
Selection.Copy

Outbook1.Activate
Outbook1.Sheets("Sheet1").Range("A1").PasteSpecial (xlPasteAll)

1 Answer 1

1

You can keep the source formatting (as long as it's not conditional formatting), using the PasteSpecial xlPasteAll command.

Recommendation: It's always better if you stay from Activate , Select and Selection, instead use referenced Workbooks and Sheets.

(for more details go to How to avoid using Select in Excel VBA macros )

Code

Option Explicit

Sub CopyBetweenSheets()

Dim Outbook1        As Workbook
Dim OutBook         As Workbook
Dim Lines           As Long

Set OutBook = ThisWorkbook
Set Outbook1 = Workbooks.Add

With OutBook
    With .Sheets("Sheet6")
        ' find last row in Column A in "Sheet6"
        Lines = .Cells(.Rows.Count, "A").End(xlUp).Row
        .Range("A1:N" & Lines).Copy
    End With
End With

' paste to "A1" in "Sheet1" in the new workbook
Outbook1.Sheets("Sheet1").Range("A1").PasteSpecial xlPasteAll

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

3 Comments

still color of each row is not copied to new workbook
@yuvaraj what color? Are u referring to conditional formatting?
@yuvaraj it's ok :) and thanks for accepting my answer

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.