VBA Code to Copy a Sheet from Workbook A and paste it on that sheet in Workbook B

UncleBajubjubs

Board Regular
Joined
Jul 11, 2017
Messages
111
Office Version
  1. 2010
Hello, I have a large workbook which does a ton of engineering calculations to select which parts to use in a construction product. One sheet in this workbook contains a list of parts, which I'd like to copy to another workbook which handles the pricing and ordering.

Essentially, I want a macro to copy 'Bill of Materials' from 'Engineering Workbook' and have it paste it over 'Bill of Materials' in 'Purchasing Workbook'. There's only two named ranged that need to be copied over, and it doesn't need the formulas to still work, just their values (so, if a cell contains formula '3*4', i just want to copy over '12'). How would I go about doing this in the simplest way possible.

Thanks.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Give this code a try. Let me know if there are any issues with it.
You will need to edit this line of code: fileloc = "C:". Enter the folder location where the file "Engineering Workbook" exists.

Code:
Option Explicit


Sub CopyMaterials()
Dim cfwb As Workbook
Dim fileloc As String


Application.DisplayAlerts = False
On Error Resume Next
ThisWorkbook.Sheets("Bill of Materials").UsedRange.Clear
Application.DisplayAlerts = True


[COLOR=#ff0000]fileloc = "C:\"[/COLOR]
Workbooks.Open fileloc & "Engineering Workbook"
Set cfwb = Workbooks("Engineering Workbook")
cfwb.Sheets("Bill of Materials").UsedRange.Copy
ThisWorkbook.Sheets("Bill of Materials").Range("A1").PasteSpecial xlPasteValues
End Sub
'
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top