Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-09-2018, 09:42 PM
LearnerExcel LearnerExcel is offline Copy data as well as formatting from one workbook to another. Windows 7 32bit Copy data as well as formatting from one workbook to another. Office 2013
Advanced Beginner
Copy data as well as formatting from one workbook to another.
 
Join Date: Nov 2016
Posts: 81
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
  #2  
Old 03-10-2018, 01:35 PM
NoSparks NoSparks is offline Copy data as well as formatting from one workbook to another. Windows 7 64bit Copy data as well as formatting from one workbook to another. Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

Use copy and paste. Arrays don't hold formatting.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy from one workbook to another MartinExcel11 Excel Programming 1 03-28-2017 09:49 AM
automatically copy FIRST COLUMN ONLy to all sheets in workbook nrcahill Excel 1 03-14-2016 12:26 PM
data entered in one workbook should be updated in other relevant workbook based on the date vedha Excel 0 04-24-2015 08:45 PM
Copy data as well as formatting from one workbook to another. Is it possible to copy and migrate custom views from one XLS workbook to another? JustJeff Excel 1 12-19-2014 10:11 AM
Copy data as well as formatting from one workbook to another. macro to transfer data from one workbook to another workbook virsojour Excel Programming 5 02-01-2011 08:58 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:15 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft