Copy formulas & values to new workbook

pingme89

Board Regular
Joined
Jan 23, 2014
Messages
176
Office Version
  1. 365
Platform
  1. Windows
There are many examples of copying data from one Workbook to another. However, I have a complex problem.
The source workbook has many sheets. The range of cells I need copy are from A1:P5 ONLY. Some of the cells have links to other sheets on the same source workbook and some are just formulas. The cells that have links to other sheets, I DO NOT want to copy the link. I just want to copy the value of the cell.

For instance in the source worksheet, one cell might contain "=A5*A6". I would need this formula to be copied over to the new spreadsheet.

However, there are other cells with contents such as, "=Worksheets(1).Range("A5").value * B3". In this situation I need only the value of the cell and not the formula copied to the new spreadsheet.

Having said that, I do know which cells need the formula copied and which cells need only the value copied over.

The range which the formulas need to be copied over are: A1:P2,G3:G4,J3:P4,A5:P5
The range whicn I only need the value copied over are: A3:F4,G3:I4

I can't find a way to copy 2 types of data. Can someone help me find an elegant solution?

So far this is what I have:

Private Sub Export_Click()
Dim wkbSrc As Workbook
Dim wkbDst As Workbook
Dim ws As String
Dim WBN As String
Dim ID As String
Dim SDrv As String
Dim DDrv As String
Dim Sfname As String
Dim Dfname As String




Dim DateStr As String
Dim DirPath As String
Dim Client As String
Dim ClientInfo


Dim WBName As String
Dim WBNameX As String


WBN = ThisWorkbook.Name




Client = Application.Workbooks(WBN).Worksheets(3).Range("F3")
ID = Application.Workbooks(WBN).Worksheets(1).Range("A7")


MsgBox Client
MsgBox ID


Workbooks.Add
DirPath = "D:\Estimates\"
DateStr = Format(Date, "MMMM dd, yyyy")
Rem Format(Date, "yyyy-mm-dd")


Rem WBName is the NEW Estimate Workbook Name


WBName = DateStr & " " & Client & " SUPP " & ID
MsgBox WBName
WBNameX = DateStr & " " & Client & " SUPP " & ID & ".xlsx"
MsgBox WBNameX




Rem Set this to the relevant worksheet
ActiveWorkbook.SaveAs DirPath & WBName & ".xlsx", FileFormat:=51
Rem ActiveWorkbook.SaveAs Filename:=DirPath & WBName & ".xlsx"




SDrv = "D:\Estimates\"
Sfname = ActiveWorkbook.Name

DDrv = "D:\Estimates\"
Dfname = WBNameX


Set wkbSrc = Workbooks.Open(SDrv & Sfname)
Set wkbDst = Workbooks.Open(DDrv & Dfname)

Application.DisplayAlerts = False









With wkbDst
.Save
Rem .Close


End With
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I have an idea ... break the external links in the source workbook, copy all required cells as one block, paste, looping as required. Close the source workbook without saving.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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