VBA to run multiple macros on different sheets

ldaly4

New Member
Joined
May 3, 2022
Messages
2
Office Version
  1. 2021
Platform
  1. Windows
I have 6 macros that I was to run sequentially however I'd like to run the first 4 on one shirt, open the second sheet and then run the last two macros. Macro 5 copies information from sheet one to sheet two. I would like to have one button that can do all of this in one go. I will attach the VBA code I've tried so far below - this does all of the commands but doesn't move on to the next sheet

VBA Code:
Sub Button1_Click()

    With Sheet7
        Call Macro1 'Macro1
        Call Macro2 'Macro2
        Call Macro3 'Macro3
        Call Macro4 'Macro4
        
    End With
   
     With Sheet8
        Call Macro5 'Macro5
        Call Macro6 'Macro6
End With
End sub
        
    End With
    
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Edit code:
VBA Code:
Sub Button1_Click()

    With Sheet7
        Call Macro1 'Macro1
        Call Macro2 'Macro2
        Call Macro3 'Macro3
        Call Macro4 'Macro4
        
    End With
   
     With Sheet8
        Call Macro5 'Macro5
        Call Macro6 'Macro6

    End With
    
End Sub
 
Upvote 0
Your With Sheet / End with lines are not actually doing anything.

The below seems to be what you are trying to do. Not ideal coding practice, the macros should not require the sheets to be activated but it sounds like they do.
Also you are using the Sheet code name which can be different to the name the user sees and that is fine as long as you understand that.

VBA Code:
Sub Button1_Click()

    Application.ScreenUpdating = False
    Dim wsCurrent As Worksheet
    Set wsCurrent = ActiveSheet
    
    Sheet7.Activate
        Call Macro1 'Macro1
        Call Macro2 'Macro2
        Call Macro3 'Macro3
        Call Macro4 'Macro4
   
    Sheet8.Activate
        Call Macro5 'Macro5
        Call Macro6 'Macro6

    wsCurrent.Activate
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,685
Members
448,978
Latest member
rrauni

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