Excel VBA Export to Excel sheet but remove formulas
up vote
0
down vote
favorite
I have a piece of VBA that is exporting 3 tabs to an excel Workbook daily. I have a piece of script that removed all external links which is great. however I am wondering if there is another piece of code that will allow me to also remove formulas. There is a formula on the field headers that are calculating dates.
So instead of just Showing NOV 7, it is still showing the formula =Today()-1
In my VBA I'd like to include code that would just include the value of "Nov 7" rather than the formula.
The script I have is below
'excel read only
Application.DisplayAlerts = False
Sheets(Array("Template", "Data Export", "Sales Breakdown")).Copy
Dim ExternalLinks As Variant
Dim x As Long
'Create an Array of all External Links stored in Workbook
ExternalLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks)
'Loop Through each External Link in ActiveWorkbook and Break it
For x = 1 To UBound(ExternalLinks)
ActiveWorkbook.BreakLink Name:=ExternalLinks(x), Type:=xlLinkTypeExcelLinks
Next x
ActiveWorkbook.SaveAs Filename:="MY FILENAME", FileFormat:=51, CreateBackup:=False
excel vba export
add a comment |
up vote
0
down vote
favorite
I have a piece of VBA that is exporting 3 tabs to an excel Workbook daily. I have a piece of script that removed all external links which is great. however I am wondering if there is another piece of code that will allow me to also remove formulas. There is a formula on the field headers that are calculating dates.
So instead of just Showing NOV 7, it is still showing the formula =Today()-1
In my VBA I'd like to include code that would just include the value of "Nov 7" rather than the formula.
The script I have is below
'excel read only
Application.DisplayAlerts = False
Sheets(Array("Template", "Data Export", "Sales Breakdown")).Copy
Dim ExternalLinks As Variant
Dim x As Long
'Create an Array of all External Links stored in Workbook
ExternalLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks)
'Loop Through each External Link in ActiveWorkbook and Break it
For x = 1 To UBound(ExternalLinks)
ActiveWorkbook.BreakLink Name:=ExternalLinks(x), Type:=xlLinkTypeExcelLinks
Next x
ActiveWorkbook.SaveAs Filename:="MY FILENAME", FileFormat:=51, CreateBackup:=False
excel vba export
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a piece of VBA that is exporting 3 tabs to an excel Workbook daily. I have a piece of script that removed all external links which is great. however I am wondering if there is another piece of code that will allow me to also remove formulas. There is a formula on the field headers that are calculating dates.
So instead of just Showing NOV 7, it is still showing the formula =Today()-1
In my VBA I'd like to include code that would just include the value of "Nov 7" rather than the formula.
The script I have is below
'excel read only
Application.DisplayAlerts = False
Sheets(Array("Template", "Data Export", "Sales Breakdown")).Copy
Dim ExternalLinks As Variant
Dim x As Long
'Create an Array of all External Links stored in Workbook
ExternalLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks)
'Loop Through each External Link in ActiveWorkbook and Break it
For x = 1 To UBound(ExternalLinks)
ActiveWorkbook.BreakLink Name:=ExternalLinks(x), Type:=xlLinkTypeExcelLinks
Next x
ActiveWorkbook.SaveAs Filename:="MY FILENAME", FileFormat:=51, CreateBackup:=False
excel vba export
I have a piece of VBA that is exporting 3 tabs to an excel Workbook daily. I have a piece of script that removed all external links which is great. however I am wondering if there is another piece of code that will allow me to also remove formulas. There is a formula on the field headers that are calculating dates.
So instead of just Showing NOV 7, it is still showing the formula =Today()-1
In my VBA I'd like to include code that would just include the value of "Nov 7" rather than the formula.
The script I have is below
'excel read only
Application.DisplayAlerts = False
Sheets(Array("Template", "Data Export", "Sales Breakdown")).Copy
Dim ExternalLinks As Variant
Dim x As Long
'Create an Array of all External Links stored in Workbook
ExternalLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks)
'Loop Through each External Link in ActiveWorkbook and Break it
For x = 1 To UBound(ExternalLinks)
ActiveWorkbook.BreakLink Name:=ExternalLinks(x), Type:=xlLinkTypeExcelLinks
Next x
ActiveWorkbook.SaveAs Filename:="MY FILENAME", FileFormat:=51, CreateBackup:=False
excel vba export
excel vba export
asked Nov 8 at 20:19
Jason Yuen
153
153
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
How about:
Sub FormulaKiller()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
With sh.Cells
.Copy
.PasteSpecial xlPasteValuesAndNumberFormats
End With
Next sh
End Sub
would this be placed in between the code I had posted?
– Jason Yuen
Nov 8 at 20:56
@JasonYuen Right before .SaveAs
– Gary's Student
Nov 8 at 20:59
Awesome this works great! Thank you so much!
– Jason Yuen
Nov 9 at 14:46
add a comment |
up vote
0
down vote
Another approach:
On Error Resume Next
Set FormulaCells = ActiveSheet.UsedRange.SpecialCells(xlFormulas, 23)
' Exit if no formulas are found
If FormulaCells Is Nothing Then
Exit Sub
End If
For Each myCell In FormulaCells
myCell.Value = myCell.Value
Next myCell
add a comment |
up vote
0
down vote
right after you copy you can refer to value of the old workbook to change the stuff to value.
something like
Dim wb1, wb2 As Workbook
Set wb1 = ActiveWorkbook
wb1.Sheets(Array("Template", "Data Export", "Sales Breakdown")).Copy
Set wb2 = ActiveWorkbook 'the new workbook is now wb2
For Each i In Array("Template", "Data Export", "Sales Breakdown")
wb2.Sheets(i).usedrange.Value = wb1.Sheets(i).usedrange.Value
Next
///rest of yourcode///
or if you have the exact range you can use range("A1:Z500") instead of usedrange to make it faster. Using this method you can avoid using copy&paste value (which i hate). and instead of activeworkbook you can use wb2 in your below code.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
How about:
Sub FormulaKiller()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
With sh.Cells
.Copy
.PasteSpecial xlPasteValuesAndNumberFormats
End With
Next sh
End Sub
would this be placed in between the code I had posted?
– Jason Yuen
Nov 8 at 20:56
@JasonYuen Right before .SaveAs
– Gary's Student
Nov 8 at 20:59
Awesome this works great! Thank you so much!
– Jason Yuen
Nov 9 at 14:46
add a comment |
up vote
1
down vote
accepted
How about:
Sub FormulaKiller()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
With sh.Cells
.Copy
.PasteSpecial xlPasteValuesAndNumberFormats
End With
Next sh
End Sub
would this be placed in between the code I had posted?
– Jason Yuen
Nov 8 at 20:56
@JasonYuen Right before .SaveAs
– Gary's Student
Nov 8 at 20:59
Awesome this works great! Thank you so much!
– Jason Yuen
Nov 9 at 14:46
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
How about:
Sub FormulaKiller()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
With sh.Cells
.Copy
.PasteSpecial xlPasteValuesAndNumberFormats
End With
Next sh
End Sub
How about:
Sub FormulaKiller()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
With sh.Cells
.Copy
.PasteSpecial xlPasteValuesAndNumberFormats
End With
Next sh
End Sub
answered Nov 8 at 20:30
Gary's Student
71.4k93460
71.4k93460
would this be placed in between the code I had posted?
– Jason Yuen
Nov 8 at 20:56
@JasonYuen Right before .SaveAs
– Gary's Student
Nov 8 at 20:59
Awesome this works great! Thank you so much!
– Jason Yuen
Nov 9 at 14:46
add a comment |
would this be placed in between the code I had posted?
– Jason Yuen
Nov 8 at 20:56
@JasonYuen Right before .SaveAs
– Gary's Student
Nov 8 at 20:59
Awesome this works great! Thank you so much!
– Jason Yuen
Nov 9 at 14:46
would this be placed in between the code I had posted?
– Jason Yuen
Nov 8 at 20:56
would this be placed in between the code I had posted?
– Jason Yuen
Nov 8 at 20:56
@JasonYuen Right before .SaveAs
– Gary's Student
Nov 8 at 20:59
@JasonYuen Right before .SaveAs
– Gary's Student
Nov 8 at 20:59
Awesome this works great! Thank you so much!
– Jason Yuen
Nov 9 at 14:46
Awesome this works great! Thank you so much!
– Jason Yuen
Nov 9 at 14:46
add a comment |
up vote
0
down vote
Another approach:
On Error Resume Next
Set FormulaCells = ActiveSheet.UsedRange.SpecialCells(xlFormulas, 23)
' Exit if no formulas are found
If FormulaCells Is Nothing Then
Exit Sub
End If
For Each myCell In FormulaCells
myCell.Value = myCell.Value
Next myCell
add a comment |
up vote
0
down vote
Another approach:
On Error Resume Next
Set FormulaCells = ActiveSheet.UsedRange.SpecialCells(xlFormulas, 23)
' Exit if no formulas are found
If FormulaCells Is Nothing Then
Exit Sub
End If
For Each myCell In FormulaCells
myCell.Value = myCell.Value
Next myCell
add a comment |
up vote
0
down vote
up vote
0
down vote
Another approach:
On Error Resume Next
Set FormulaCells = ActiveSheet.UsedRange.SpecialCells(xlFormulas, 23)
' Exit if no formulas are found
If FormulaCells Is Nothing Then
Exit Sub
End If
For Each myCell In FormulaCells
myCell.Value = myCell.Value
Next myCell
Another approach:
On Error Resume Next
Set FormulaCells = ActiveSheet.UsedRange.SpecialCells(xlFormulas, 23)
' Exit if no formulas are found
If FormulaCells Is Nothing Then
Exit Sub
End If
For Each myCell In FormulaCells
myCell.Value = myCell.Value
Next myCell
answered Nov 8 at 20:32
cybernetic.nomad
1,9851515
1,9851515
add a comment |
add a comment |
up vote
0
down vote
right after you copy you can refer to value of the old workbook to change the stuff to value.
something like
Dim wb1, wb2 As Workbook
Set wb1 = ActiveWorkbook
wb1.Sheets(Array("Template", "Data Export", "Sales Breakdown")).Copy
Set wb2 = ActiveWorkbook 'the new workbook is now wb2
For Each i In Array("Template", "Data Export", "Sales Breakdown")
wb2.Sheets(i).usedrange.Value = wb1.Sheets(i).usedrange.Value
Next
///rest of yourcode///
or if you have the exact range you can use range("A1:Z500") instead of usedrange to make it faster. Using this method you can avoid using copy&paste value (which i hate). and instead of activeworkbook you can use wb2 in your below code.
add a comment |
up vote
0
down vote
right after you copy you can refer to value of the old workbook to change the stuff to value.
something like
Dim wb1, wb2 As Workbook
Set wb1 = ActiveWorkbook
wb1.Sheets(Array("Template", "Data Export", "Sales Breakdown")).Copy
Set wb2 = ActiveWorkbook 'the new workbook is now wb2
For Each i In Array("Template", "Data Export", "Sales Breakdown")
wb2.Sheets(i).usedrange.Value = wb1.Sheets(i).usedrange.Value
Next
///rest of yourcode///
or if you have the exact range you can use range("A1:Z500") instead of usedrange to make it faster. Using this method you can avoid using copy&paste value (which i hate). and instead of activeworkbook you can use wb2 in your below code.
add a comment |
up vote
0
down vote
up vote
0
down vote
right after you copy you can refer to value of the old workbook to change the stuff to value.
something like
Dim wb1, wb2 As Workbook
Set wb1 = ActiveWorkbook
wb1.Sheets(Array("Template", "Data Export", "Sales Breakdown")).Copy
Set wb2 = ActiveWorkbook 'the new workbook is now wb2
For Each i In Array("Template", "Data Export", "Sales Breakdown")
wb2.Sheets(i).usedrange.Value = wb1.Sheets(i).usedrange.Value
Next
///rest of yourcode///
or if you have the exact range you can use range("A1:Z500") instead of usedrange to make it faster. Using this method you can avoid using copy&paste value (which i hate). and instead of activeworkbook you can use wb2 in your below code.
right after you copy you can refer to value of the old workbook to change the stuff to value.
something like
Dim wb1, wb2 As Workbook
Set wb1 = ActiveWorkbook
wb1.Sheets(Array("Template", "Data Export", "Sales Breakdown")).Copy
Set wb2 = ActiveWorkbook 'the new workbook is now wb2
For Each i In Array("Template", "Data Export", "Sales Breakdown")
wb2.Sheets(i).usedrange.Value = wb1.Sheets(i).usedrange.Value
Next
///rest of yourcode///
or if you have the exact range you can use range("A1:Z500") instead of usedrange to make it faster. Using this method you can avoid using copy&paste value (which i hate). and instead of activeworkbook you can use wb2 in your below code.
edited Nov 9 at 1:14
answered Nov 9 at 1:09
Osman Wong
595
595
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53215532%2fexcel-vba-export-to-excel-sheet-but-remove-formulas%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown