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
My name is Vishwamitra Mishra. Friends Call me Vishwa. This blog is authored by me. I am an Excel Geek. Well, this blog talks a lot about my passion in Excels & Macros so I’ll not talk about it :) I am very much passionate about traveling & quite recently discovered that I am a good photographer too..:P
AND GET A FREE!
E-BOOK FOR EXCEL VBA BEGINNERS
DON'T MISS ANY NEW ARTICLE !
Get your FREE! E-Book & Have Every New Article Delivered Straight To Your Email-Box