Reputation: 15044
Below code copies data(as well as formatting) from source range to target range.
Set RngTemplate = ActiveWorkbook.Worksheets("Template").Range("A1:AD1")
Set RngTarget = ActiveWorkbook.Worksheets("File1").Range("A1:AD1")
RngTemplate.Copy RngTarget
But I also want the cell widths to be copied to target range, any idea how to implement it.
Upvotes: 1
Views: 573
Reputation: 17637
Use the .PasteSpecial()
method
Set RngTemplate = ActiveWorkbook.Worksheets("Template").Range("A1:AD1")
Set RngTarget = ActiveWorkbook.Worksheets("File1").Range("A1:AD1")
RngTemplate.Copy
RngTarget.PasteSpecial
RngTarget.PasteSpeical xlPasteColumnWidths
Application.CutCopyMode = False
Upvotes: 1