Run one macro for all macros instead of doing it one by one

krodriguez

Board Regular
Joined
Jul 11, 2012
Messages
119
Hello,

I have the following code with 2 macros and will like to run it all at once, how can I do this? Thanks

Sub SaveSheetsAsFiles()
Dim SheetsToSave
SheetsToSave = Array("Rainbow", "RLN-Net Realization", "RLN-Red Rev", "RLN-COGS", "RLN-Logistics", "RLN-R&D", "RLN-Selling", "RLN-Administrative", "RLN-Advertising", "RLN-Sales Promo") 'change tab names to suit
Application.ScreenUpdating = False
For Each sht In Sheets(SheetsToSave)
sht.Copy
'file location is same as workbook the code is in. Change to suit
'file format is .xlsm - change to suit
ActiveWorkbook.SaveAs Filename:=sht.Name & ".xlsm", FileFormat:=52
Next sht
Application.ScreenUpdating = True
End Sub


Sub SaveSheetsAsFiles2()
Dim SheetsToSave
SheetsToSave = Array("Neocell", "NC-Net Realization", "NC-Red Rev", "NC-COGS NC-Logistics", "NC-R&D", "NC-Selling", "NC-Administrative", "NC-Advertising", "NC-Sales Promo") 'change tab names to suit
Application.ScreenUpdating = False
For Each sht In Sheets(SheetsToSave)
sht.Copy
'file location is same as workbook the code is in. Change to suit
'file format is .xlsm - change to suit
ActiveWorkbook.SaveAs Filename:=sht.Name & ".xlsm", FileFormat:=52
Next sht
Application.ScreenUpdating = True
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
All you need to do is add the values from the 2nd macro's array to the 1st macro's array
 
Upvote 0
You need to add these values
Code:
"Neocell", "NC-Net Realization", "NC-Red Rev", "NC-COGS", "NC-Logistics",  "NC-R&D", "NC-Selling", "NC-Administrative", "NC-Advertising",  "NC-Sales Promo"
to the array in your first code.
 
Upvote 0
but if I do that I would have one excel file per value correct? what I'm looking is to run a code that add each array to one excel file. So I run the macro and the final output will be two excel files that will have the following tabs on each one:

1. "Rainbow", "RLN-Net Realization", "RLN-Red Rev", "RLN-COGS", "RLN-Logistics", "RLN-R&D", "RLN-Selling", "RLN-Administrative", "RLN-Advertising", "RLN-Sales Promo"

2.
"Neocell", "NC-Net Realization", "NC-Red Rev", "NC-COGS NC-Logistics", "NC-R&D", "NC-Selling", "NC-Administrative", "NC-Advertising", "NC-Sales Promo"
 
Upvote 0
Your code is saving each sheet as a new workbook.
If that is not what you want, why did you not say so in your op?
 
Upvote 0
What do you want to call the new workbooks?
 
Upvote 0
I used to just record a macro that manually runs both macros one after the other. Rather lazy way of doing it but it does the job
 
Upvote 0
First workbook Rainbow with these sheets:

1. "Rainbow", "RLN-Net Realization", "RLN-Red Rev", "RLN-COGS", "RLN-Logistics", "RLN-R&D", "RLN-Selling", "RLN-Administrative", "RLN-Advertising", "RLN-Sales Promo"

Second workbook Neocell with these sheets:

2.
"Neocell", "NC-Net Realization", "NC-Red Rev", "NC-COGS NC-Logistics", "NC-R&D", "NC-Selling", "NC-Administrative", "NC-Advertising", "NC-Sales Promo"
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
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