Some times, we require a single control or Button which can perform different action on first click and some other Action on the second click. This can be achieved by adding Toggle Button in your Excel Workbook.
How to Add Toggle Button in Excel Workbook:
It’s very easy to add Toggle Button in your workbook. Follow the below steps to add toggle button:
I am going to explain you by giving two examples, how we can use this button in real time applications.
Private Sub ToggleButton1_Click() 'For hiding and un-hiding Columns Columns("C:F").Hidden = Not Columns("C:F").Hidden 'For hiding and un-hiding Rows Rows("1:2").Hidden = Not Rows("1:2").Hidden End Sub
i) Add the Code of sorting in Ascending and Descending in a Regular Module in VBE of your Workbook
ii) Paste the below code in the VBE of the Worksheet where you have Put your button:
Private Sub ToggleButton1_Click() If ToggleButton1.Value = True Then Call Sort_Ascending Else Call Sort_Descending End If End Sub
To Check out more Excel Macro Tutorials, visit Excel Macro Tutorial