VBA Save sheet with new name and change formula to values in selected cells

CCoetzee

New Member
Joined
Apr 17, 2021
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Morning

i'm using the below to save my spreadsheet with a new name and location.

Sub SaveInWithNewName()
Dim NewFN As Variant
' Copy Invoice to a new workbook
ActiveSheet.Copy
ActiveSheet.Shapes("Rounded Rectangle 1").Delete
NewFN = "C:\Users\Fonnie\Dropbox\Ck007 Mechanical\Invoices\" & " " & Range("G2").Value & " " & Range("B11").Value & " " & Range("E11").Value & " " & Range("E12").Value & " " & Range("E2").Value & ".xlsm"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbookMacroEnabled
ActiveWorkbook.Close

End Sub


But what i need is when i save my worksheet the formulas in cells (B20:G60) must be saved as values.

can you please assist?

Regards Christelle
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try adding this line in this position:
VBA Code:
ActiveSheet.Copy
Range("B20:G60").Value = Range("B20:G60").Value         '<<< ADD HERE
   ActiveSheet.Shapes("Rounded Rectangle 1").Delete

Bye
 
Upvote 0
Thank you

If i add the code it removes the formulas from my "master" sheet and saves the copy with the formulas?

The copy must be saved without formulas and my "master" sheet must keep the formulas.

Any idea why this is happening?

Regards Christelle
 
Upvote 0
And also, which "vba module" contains your Sub SaveInWithNewName? It is in the header of the vba window, after "Microsoft Visual Basic Application Edition, ...."
Bye
 
Upvote 0
Hi,​
first obviously use SaveCopyAs rather than SaveAs ! Then open the new workbook and replace formulas by values and save the workbook …​
 
Upvote 0
I guess that CCoetzee has no problem in saving a copy of the worksheet (the sheet has just been copied in a new workbook using the command ActiveSheet.Copy), but he needs to save values and not formulas.
My current "guess" is that he tried to say that my added line of code leave the copied sheet with the formulas, whereas it remove the formulas from the master sheet (he terminated the phrase by a question mark, but probably was willing to use the exclamation mark).
And my final "best guess" is that he inserted the code into a vba class module, rather then a vba standard module; if this is the case then my Range("B20:G60") will refer to the object the class module refers to and not the activesheet.
If these guesses are correct then my preferred suggestion is to move the code to a vba "standard module" (the ones you create by using the command Menu /Insert /Module), or to use
Code:
ActiveSheet.Range("B20:G60").Value = ActiveSheet.Range("B20:G60").Value

I write these information because it seems that we and the OP have non-overlapping timezones, so that a full day is needed before we can get an answer to the questions posed.

Bye
 
Upvote 0
Yes you are right, in particular if the original worbook has several worksheets. But for only one another way is SaveCopyAs …​
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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