VBA Help

excel_learnerz

Board Regular
Joined
Dec 12, 2018
Messages
73
Hello amazing people,

I was wondering can you help me with the below

This is a current macro that I am using that copies everything (format, tab names, add data) and doesn't have formulas, removes the macros from the file also, works wonderfully, but is there a way to save the new excel into the same location automatically instead of manually saving it

Sub formula_removal()
Dim anySheet As Worksheet
ActiveWorkbook.Sheets.Copy
For Each anySheet In ActiveWorkbook.Worksheets
anySheet.UsedRange.Copy
anySheet.UsedRange.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Next
Application.DisplayAlerts = False
Sheets("sheet4").Delete
Sheets("sheet5").Delete
Sheets("sheet6").Delete
Sheets("sheet7").Delete
Sheets("sheet8").Delete
Sheets("sheet9").Delete
Sheets("sheet10").Delete
Sheets("sheet11").Delete
Application.DisplayAlerts = True

End Sub


Thanks
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
This is untested but might point you in the right direction:
Code:
Sub formula_removal()
Dim anySheet As Worksheet
Dim sPath As String 'path of current workbook
Dim sSaveAs As String 'file name to save as


    sPath = ThisWorkbook.Path & "\" 'path of current book
    sSaveAs = "YOURFILENAME" 'change as required
    
    ActiveWorkbook.Sheets.Copy
    ActiveWorkbook.SaveAs Filename:=sPath & sSaveAs, FileFormat:=xlOpenXMLWorkbook
    For Each anySheet In ActiveWorkbook.Worksheets
    anySheet.UsedRange.Copy
    anySheet.UsedRange.PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    Next
    Application.DisplayAlerts = False
    Sheets("sheet4").Delete
    Sheets("sheet5").Delete
    Sheets("sheet6").Delete
    Sheets("sheet7").Delete
    Sheets("sheet8").Delete
    Sheets("sheet9").Delete
    Sheets("sheet10").Delete
    Sheets("sheet11").Delete
    Application.DisplayAlerts = True


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,935
Messages
6,175,494
Members
452,649
Latest member
mr_bhavesh

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