VBA To Copy a sheet into another workbook with formulas without reference

drop05

Active Member
Joined
Mar 23, 2021
Messages
285
Office Version
  1. 365
Platform
  1. Windows
Hello, i am wondering if there is a way that when copying a sheet into a new workbook, and the sheet i am copying has formulas. Is there a way to do this and not have the references in the formula of the new workbook when bringing the copy over?

Here is the code i use to make the tab in the new workbook.


VBA Code:
    'Create new template
    Set wbNew = Workbooks.Add
    Set wsNewTemp1 = wbNew.Worksheets("Sheet1")
    wsNewTemp1.Name = "Calculation"
    ThisWorkbook.Sheets("Calculation").Range("A1:EW1").EntireColumn.Copy
    wsNewTemp1.Range("A1").PasteSpecial Paste:=xlPasteAll
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Use xlPasteValues instead of xlPasteAll

VBA Code:
'Create new template
    
Set wbNew = Workbooks.Add
    Set wsNewTemp1 = wbNew.Worksheets("Sheet1")
    wsNewTemp1.Name = "Calculation"
    ThisWorkbook.Sheets("Calculation").Range("A1:EW1").EntireColumn.Copy
    wsNewTemp1.Range("A1").PasteSpecial Paste:=xlPasteValues
    Range("A1").Select
    Application.CutCopyMode = False
 
Upvote 0
Use xlPasteValues instead of xlPasteAll

VBA Code:
'Create new template
   
Set wbNew = Workbooks.Add
    Set wsNewTemp1 = wbNew.Worksheets("Sheet1")
    wsNewTemp1.Name = "Calculation"
    ThisWorkbook.Sheets("Calculation").Range("A1:EW1").EntireColumn.Copy
    wsNewTemp1.Range("A1").PasteSpecial Paste:=xlPasteValues
    Range("A1").Select
    Application.CutCopyMode = False
Thank you, is there a way to use it for the vba code below, when using the below code it is bringing over the external references in the formulas, i would like to keep the formulas when bring them over but without the external references and not just values

VBA Code:
        Workbooks.Add
        ThisWorkbook.Worksheets(shtUnit.Name).Copy before:=ActiveWorkbook.Worksheets("Sheet1")
 
Upvote 0
Can you let us know what the formula's are and where they are?

Are you able to use Xl2BB.

1685687213793.png
 
Upvote 0
Hi drop05
Try this method I think it do the trick
Run this code when the sheet you want to copy
VBA Code:
Sub test()
 Cells.SpecialCells(xlCellTypeFormulas, 23).Replace What:="=", Replacement:=Chr(135) & "="
 Sheets("Sheet1").Copy
 Cells.Replace What:=Chr(135) & "=", Replacement:="="
ThisWorkbook.Sheets("Sheet1").Cells.Replace What:=Chr(135) & "=", Replacement:="="
End Sub
 
Upvote 0
Hi drop05
Try this method I think it do the trick
Run this code when the sheet you want to copy
VBA Code:
Sub test()
 Cells.SpecialCells(xlCellTypeFormulas, 23).Replace What:="=", Replacement:=Chr(135) & "="
 Sheets("Sheet1").Copy
 Cells.Replace What:=Chr(135) & "=", Replacement:="="
ThisWorkbook.Sheets("Sheet1").Cells.Replace What:=Chr(135) & "=", Replacement:="="
End Sub
yes this helps bring the formula over, however the formula is staying as ‡= after the vba is ran, is there a way to turn it back into a formula
 
Upvote 0
The code above does every thing in here
VBA Code:
Sub test()
 Cells.SpecialCells(xlCellTypeFormulas, 23).Replace What:="=", Replacement:=Chr(135) & "=" '<< This line to replace in the source sheet
 Sheets("Sheet1").Copy ' Sopy to a new book
 Cells.Replace What:=Chr(135) & "=", Replacement:="=" ' Replace in the new book so you get back to formulas
ThisWorkbook.Sheets("Sheet1").Cells.Replace What:=Chr(135) & "=", Replacement:="=" 'Replace in the source book so you get back to formulas
End Sub
 
Upvote 0
The code above does every thing in here
VBA Code:
Sub test()
 Cells.SpecialCells(xlCellTypeFormulas, 23).Replace What:="=", Replacement:=Chr(135) & "=" '<< This line to replace in the source sheet
 Sheets("Sheet1").Copy ' Sopy to a new book
 Cells.Replace What:=Chr(135) & "=", Replacement:="=" ' Replace in the new book so you get back to formulas
ThisWorkbook.Sheets("Sheet1").Cells.Replace What:=Chr(135) & "=", Replacement:="=" 'Replace in the source book so you get back to formulas
End Sub
Hi sorry for the late ask, but have been trying to trouble shoot this but around here

Cells.Replace What:=Chr(135) & "=", Replacement:="=" ' Replace in the new book so you get back to formulas

the code is not replacing the new workbooks formulas it is leaving them as below

‡=SUBTOTAL(109,tbl_ExpbyFiling[TI (Line 30)])

and not getting rid of the ‡

this is in regards to the external workbook it is creating, the workbook the mod is in works good
 
Upvote 0
Hi
Then try this
VBA Code:
Sub test()
 Cells.SpecialCells(xlCellTypeFormulas, 23).Replace What:="=", Replacement:=Chr(135) & "=" '<< This line to replace in the source sheet
 Sheets("Sheet1").Copy ' Sopy to a new book
 ActiveWorkbook.Sheets("sheet1").Cells.Replace What:=Chr(135) & "=", Replacement:="=" ' Replace in the new book so you get back to formulas
ThisWorkbook.Sheets("Sheet1").Cells.Replace What:=Chr(135) & "=", Replacement:="=" 'Replace in the source book so you get back to formulas
End Sub
 
Upvote 0
Hi drop05 and mohadin. Trial passing the sheet in a collection. HTH. Dave
Code:
Dim WbNew As Workbook, ShtCollect As Collection
Set ShtCollect = New Collection
ShtCollect.Add ThisWorkbook.Sheets("Sheet1")
Set WbNew = Workbooks.Add
ShtCollect(1).Copy before:=WbNew.Sheets("Sheet1")
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,195
Members
452,616
Latest member
intern444

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