Toggle Button Between Two Macros

cdharguth

New Member
Joined
Mar 6, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello,

I currently have two separate macros which unhide different portions of a sheet. Both portions clear space for users to input data which is linked elsewhere in the workbook. The first macro is named "Add Project 2" and the second macro is named "Add Project 3." Rather than have two separate buttons for this function, I would rather have one button that toggles between the two macros and switches from "Add Project 2" to "Add Project 3" after clicking. Any guidance is appreciated. Below is the separate code I have right now.

"Add Project 2"

VBA Code:
Sub NewProject()
Application.ScreenUpdating = False
Rows("25:45").Hidden = False
Sheets("Inputs").Shapes("BackToTop").Visible = True
Sheets("Inputs").Shapes("BackToTop2").Visible = True
ActiveWindow.SmallScroll Down:=24
Application.ScreenUpdating = True
End Sub

"Add Project 3"

VBA Code:
Sub NewProject2()
Application.ScreenUpdating = False
Rows("47:67").Hidden = False
Sheets("Inputs").Shapes("BackToTop4").Visible = True
Sheets("Inputs").Shapes("BackToTop3").Visible = True
ActiveWindow.SmallScroll Down:=46
Application.ScreenUpdating = True
End Sub
 

Attachments

  • Macro Buttons.PNG
    Macro Buttons.PNG
    17.6 KB · Views: 24
  • Add Project 2.PNG
    Add Project 2.PNG
    20.6 KB · Views: 25
  • Add Project 3.PNG
    Add Project 3.PNG
    21 KB · Views: 23

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
VBA Code:
Private Sub ToggleButton1_Click()
    With ToggleButton1
        If .Value Then
            Call FirstSub
            .Caption = "Second"
        Else
            Call SecondSub
            .Caption = "First"
        End If
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

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