VBA :How to save multiple sheet into another excel file and removing formula upon saving

JOHATUP

New Member
Joined
May 26, 2023
Messages
38
Office Version
  1. 2013
Platform
  1. Windows
I have this excel sheet: Data, Pivot, Posted sheets that I need to save in one file excluding other sheet. I was able to save the file however the formula still there upon saving, I need the data of the original file to be intact so that what will be save is the correct value/data.?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
This macro will create the new file with values only.
VBA Code:
Sub SaveSheets()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    Sheets(Array("Data", "Pivot", "Posted")).Copy
    For Each ws In Sheets
        ws.UsedRange.Value = ws.UsedRange.Value
    Next ws
    Application.ScreenUpdating = False
End Sub
 
Upvote 0
This macro will create the new file with values only.
VBA Code:
Sub SaveSheets()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    Sheets(Array("Data", "Pivot", "Posted")).Copy
    For Each ws In Sheets
        ws.UsedRange.Value = ws.UsedRange.Value
    Next ws
    Application.ScreenUpdating = False
End Sub
It woks saving the selected sheets. but the formula still there because the data is linked/vlookup sheet that is not included in the saved excel file.
 
Upvote 0
This line of code replaces all the formulae in each sheet with the cell value.
VBA Code:
ws.UsedRange.Value = ws.UsedRange.Value
I tested the macro on some dummy data with formulae and it worked properly. It would be easier to help if you could upload a copy of your file (de-sensitized if necessary) to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here.
 
Upvote 0
This line of code replaces all the formulae in each sheet with the cell value.
VBA Code:
ws.UsedRange.Value = ws.UsedRange.Value
I tested the macro on some dummy data with formulae and it worked properly. It would be easier to help if you could upload a copy of your file (de-sensitized if necessary) to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here.
Im still uploading the file. thank you!
 
Upvote 0
This line of code replaces all the formulae in each sheet with the cell value.
VBA Code:
ws.UsedRange.Value = ws.UsedRange.Value
I tested the macro on some dummy data with formulae and it worked properly. It would be easier to help if you could upload a copy of your file (de-sensitized if necessary) to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here.
Dropbox
 
Upvote 0
The file you posted has two extensions (xlsx and xlsm) in the name so Excel doesn't recognize it. Please re-save the file with one extension only and re-post.
 
Upvote 0
The file you posted has two extensions (xlsx and xlsm) in the name so Excel doesn't recognize it. Please re-save the file with one extension only and re-post.
I see, you are correct idid save it incorrectly as xlsx first but i thought i did change it to xlsm. thank you for noticing. ill check on this and get back to you.
 
Upvote 0
It's an xlsm file. Just remove the .xlsx from the end & it will open.
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,575
Members
452,652
Latest member
eduedu

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