View Single Post
 
Old 03-09-2018, 09:42 PM
LearnerExcel LearnerExcel is offline Windows 7 32bit Office 2013
Advanced Beginner
 
Join Date: Nov 2016
Posts: 82
LearnerExcel will become famous soon enoughLearnerExcel will become famous soon enough
Default Copy data as well as formatting from one workbook to another.

The below code copies data from one workbook to another very nicely. But how to copy the same formatting as well.

Code:
 
Public Sub CopyValues()
Dim wb_src As Workbook
 Dim wb_dst As Workbook
 Dim ws_src As Worksheet
 Dim ws_dst As Worksheet
Set wb_src = Workbooks.Open("C:\Users\User-005\Desktop\a.xlsx")
Set wb_dst = Workbooks.Open("C:\Users\User-005\Desktop\b.xlsx")
 Set ws_src = wb_src.Sheets(1)
 Set ws_dst = wb_dst.Sheets(1)
Dim data() As Variant
 Dim r_src As Range
 Dim r_dst As Range
 Set r_src = ws_src.Range("A1").Resize(1000, 6)
 Set r_dst = ws_dst.Range("A1").Resize(1000, 6)
data = r_src.Value2
 r_dst.Value2 = data
End Sub
Reply With Quote