Combine several macros into one

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
261
Hi, I need advice about combining many small macros into one macro. Below are 3 macros that basically do the same thing on different sheets - I have a total of 11 of these macros for 11 sheets. Would it be wiser to combine them into one macro? Right now I have a macro that calls all of them. If so, would I be using the "activate" sheet method or is their a better way. If you could giveme an example on these 3 then I could apply to the rest. Thanks for the help.

VBA Code:
Sub CLUTCH_BUILD_ERASEROW()
Application.ScreenUpdating = False
    Sheets("CLUTCH").Activate
    Range("A32:S5000").Clear
    Range("A25").Select
End Sub

VBA Code:
Sub CUTTER_PROD_ERASEROW()
Application.ScreenUpdating = False
    Sheets("CUTTER").Activate
    Range("A25:Z5000").Clear
    Range("A20").Select
End Sub

VBA Code:
Sub DETAIL_FORM_ERASEROW()
Application.ScreenUpdating = False
    Sheets("DETAIL FORM").Activate
    Range("A31:AE5000").Clear
    Range("A31:AE5000").Interior.color = xlNone
    Range("A11").Select
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
20,119
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
It could be done, but I note your ranges for each sheet are different.....can they be rationalised to be the same ??
AND
Is the code applying to ALL sheets in the workbook ?
Try using
VBA Code:
Sub MM1()
Sheets("CLUTCH"). Range("A32:S5000").Clear
Sheets("CUTTER"). Range("A25:Z5000").Clear
Sheets("DETAIL FORM").Range("A31:AE5000").Clear
end Sub
 

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
261
It could be done, but I note your ranges for each sheet are different.....can they be rationalised to be the same ??
AND
Is the code applying to ALL sheets in the workbook ?
Try using
VBA Code:
Sub MM1()
Sheets("CLUTCH"). Range("A32:S5000").Clear
Sheets("CUTTER"). Range("A25:Z5000").Clear
Sheets("DETAIL FORM").Range("A31:AE5000").Clear
end Sub
 

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
261
The ranges must remain as they are because each sheet is different. The code is not applied to all sheets in the workbook, so cannot loop I guess. So your code should work with my current setup?
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
20,119
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows

ADVERTISEMENT

Did you try it ??
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
20,119
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
Clad to help... (y) (y)
 

Watch MrExcel Video

Forum statistics

Threads
1,129,443
Messages
5,636,311
Members
416,912
Latest member
danluk12

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
Top