Excel Macro Tutorial : Toggle Button in Excel
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
- Excel Macro Tutorial : VBA Spin Button In the previous Article How to write Excel Macro –...
- Excel Macro Tutorial : How to add different types of controls like Text Box, Radio button, button etc. in Excel Dear Readers, This is the 3rd Article of this Excel...
- Excel Macro Tutorial : VBA Control Property In last post Excel Macro Tutorial : Visual Basic Editor...
- Excel Macro Tutorial : How to write Excel Macro – Your First Excel Macro Dear Readers, Till now we have learnt following things...
- Excel Macro Tutorial : Add Developer Tab in Excel – 2007 and 2010 In the Previous Article What is Excel Macro of Excel...