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









share|improve this question

























    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









    share|improve this question























      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









      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 8 at 20:19









      Jason Yuen

      153




      153






















          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





          share|improve this answer




















          • 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

















          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





          share|improve this answer



























            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.






            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              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

























              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





              share|improve this answer




















              • 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














              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





              share|improve this answer




















              • 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












              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





              share|improve this answer












              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






              share|improve this answer












              share|improve this answer



              share|improve this answer










              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
















              • 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












              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





              share|improve this answer
























                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





                share|improve this answer






















                  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





                  share|improve this answer












                  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






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 8 at 20:32









                  cybernetic.nomad

                  1,9851515




                  1,9851515




















                      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.






                      share|improve this answer


























                        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.






                        share|improve this answer
























                          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.






                          share|improve this answer














                          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.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 9 at 1:14

























                          answered Nov 9 at 1:09









                          Osman Wong

                          595




                          595



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

                              How do I collapse sections of code in Visual Studio Code for Windows?

                              Node.js puppeteer - Use values from array in a loop to cycle through pages