Macro to trigger another Macro

pc732015

New Member
Joined
Oct 6, 2017
Messages
14
Hi, I have a Macro (Macro1) which is created using the Macro recorder. Macro1 is used to do similar functions in each worksheet. I can actually go to each worksheet and run Macro1 but I have altogether 500 worksheets, which means I have to do 500 times. I'm thinking of creating another Macro to run Macro1 automatically on the 500 worksheets but I'm a newbie and don't know how to cycle through all the 500 worksheets. Can someone help me? Thanks.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Can you post Macro1 so we can see what it is doing? We need to know if its selecting cells on the activesheet (typical of recorded macros) or doing anything else that requires the sheet it acts on to be active.
 
Upvote 0
Sorry, I don't download from the web.
 
Upvote 0
Hi JoeMo,

I have attached 5 sample worksheets below. Pls let me know if it's possible to create a Macro to run Macro1 automatically on the 500 worksheets. Thanks.




This is Worksheet EquipmentA

ABCD
2EquipmentAPartAArea91
3EquipmentAPartAArea111
4EquipmentAPartDArea93
5EquipmentAPartFArea111
6EquipmentAPartBArea71
7EquipmentAPartAArea21
8EquipmentAPartAArea83
9EquipmentAPartAArea102
10EquipmentAPartBArea62
11EquipmentAPartAArea11
12EquipmentAPartCArea21
13EquipmentAPartAArea71
14EquipmentAPartDArea111
15EquipmentAPartGArea91
16EquipmentAPartAArea81
17EquipmentAPartBArea62
18EquipmentAPartKArea103
19EquipmentAPartAArea101
20EquipmentAPartAArea82

<tbody>
</tbody>



This is Worksheet EquipmentB
ABCD
2EquipmentBPartAArea91
3EquipmentBPartAArea82
4EquipmentBPartAArea111
5EquipmentBPartAArea101
6EquipmentBPartDArea93
7EquipmentBPartAArea81
8EquipmentBPartFArea111
9EquipmentBPartBArea62
10EquipmentBPartAArea21
11EquipmentBPartGArea91
12EquipmentBPartAArea83
13EquipmentBPartDArea111
14EquipmentBPartAArea102
15EquipmentBPartAArea71
16EquipmentBPartBArea62
17EquipmentBPartCArea21
18EquipmentBPartAArea11

<tbody>
</tbody>




This is Worksheet EquipmentC
ABCD
2EquipmentCPartAArea11
3EquipmentCPartBArea62
4EquipmentCPartAArea102
5EquipmentCPartDArea111
6EquipmentCPartGArea91
7EquipmentCPartBArea62
8EquipmentCPartBArea71
9EquipmentCPartAArea83
10EquipmentCPartAArea21
11EquipmentCPartKArea103
12EquipmentCPartAArea81
13EquipmentCPartAArea111
14EquipmentCPartAArea91

<tbody>
</tbody>



This is Worksheet EquipmentD
ABCD
2EquipmentDPartAArea11
3EquipmentDPartBArea62
4EquipmentDPartAArea102
5EquipmentDPartAArea83
6EquipmentDPartAArea21
7EquipmentDPartBArea71
8EquipmentDPartFArea111
9EquipmentDPartDArea93
10EquipmentDPartAArea111
11EquipmentDPartAArea71
12EquipmentDPartDArea111
13EquipmentDPartGArea91
14EquipmentDPartBArea62
15EquipmentDPartKArea103
16EquipmentDPartAArea81
17EquipmentDPartAArea101
18EquipmentDPartAArea82

<tbody>
</tbody>



This is Worksheet EquipmentE
ABCD
2EquipmentEPartAArea91
3EquipmentEPartAArea111
4EquipmentEPartDArea93
5EquipmentEPartFArea111
6EquipmentEPartBArea71
7EquipmentEPartAArea21
8EquipmentEPartAArea83
9EquipmentEPartAArea102
10EquipmentEPartBArea62
11EquipmentEPartAArea11
12EquipmentEPartCArea21
13EquipmentEPartAArea71
14EquipmentEPartKArea103
15EquipmentEPartAArea101
16EquipmentEPartAArea82

<tbody>
</tbody>



This is Macro1
Sub Macro1()
'
' Macro1 Macro
'


'
Range("A1").Select
ActiveCell.FormulaR1C1 = "Equipment No."
Range("B1").Select
ActiveCell.FormulaR1C1 = "Part No."
Range("C1").Select
ActiveCell.FormulaR1C1 = "Area where Part is used"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Qty"
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Application.Goto Reference:="R100C1"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=12
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("EquipmentA").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("EquipmentA").Sort.SortFields.Add Key:=Range( _
"B101:B119"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("EquipmentA").Sort
.SetRange Range("A100:D119")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWindow.SmallScroll Down:=6
Range("B100").Select
Selection.AutoFilter
ActiveSheet.Range("$A$100:$D$119").AutoFilter Field:=2, Criteria1:="PartA"
Range("A100").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Application.Goto Reference:="R200C1"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=12
End Sub​
 
Upvote 0
Firstly, what is Macro1 supposed to do?
Row 1 initially is empty but Column A-D are assigned Column Headers.

Now at row 100 I see those same headers atop Pivot tables.

Going down to row 200 I see a copy of the range A1:D10, no pivot.

Secondly, I note that the data in the other 4 sheets is different to the first. How would you anticipate that Macro1 would work with them?

Thirdly, with those two issues clarified, how would you hope to identify 500 sheets? Might it be something like "Equip 001", "Equip 002", "Equip 003", ... "Equip 500"?
 
Upvote 0
Hi Brian,

Macro1 is to allow me to see which Area of the Equipment where PartA is been used most. Pls note that the sample data that I've given here is just a portion of the actual usage. If there are a few worksheets only (each worksheet represent an Equipment), I can click on each worksheet respectively and run Macro1. But due to there are 500 worksheets, it will take me a long time to go to individual worksheet to run Macro1, so that's why I'm asking here whether if there's any possibility creating a Macro to help me. Thanks.
 
Upvote 0
Why can you not just post your Macro code here in the forum. We should not be asked to download your code from a link you have provided. Links can always be dangerous.
 
Upvote 0
Hi Brian,

Macro1 is to allow me to see which Area of the Equipment where PartA is been used most. Pls note that the sample data that I've given here is just a portion of the actual usage. If there are a few worksheets only (each worksheet represent an Equipment), I can click on each worksheet respectively and run Macro1. But due to there are 500 worksheets, it will take me a long time to go to individual worksheet to run Macro1, so that's why I'm asking here whether if there's any possibility creating a Macro to help me. Thanks.
Fine.
It is possible to run a macro across your 500 sheets (if excel allows that creation). My main consideration was about how those sheets might be named, thus my naming of "Equip 001", etc. Are you happy that Macro1 as it stands meets your requirements? If so, provide a consistent means to name your sheets; if alphabetic I guess the progress is "..z", "..aa", "..ab", etc.
 
Upvote 0

Forum statistics

Threads
1,215,365
Messages
6,124,512
Members
449,167
Latest member
jrob72684

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