{"id":12125,"date":"2012-02-09T18:01:44","date_gmt":"2012-02-09T18:01:44","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/?p=1316"},"modified":"2012-02-09T18:01:44","modified_gmt":"2012-02-09T18:01:44","slug":"toggle-button-in-excel","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/","title":{"rendered":"Excel Macro Tutorial : Toggle Button in Excel"},"content":{"rendered":"

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.
\n<\/p>\n

How to Add Toggle Button in Excel Workbook: <\/h3>\n

It’s very easy to add Toggle Button in your workbook. Follow the below steps to add toggle button:
\n<\/p>\n

Step 1. <\/h3>\n

Go to <\/p>\n

Developer’s Tab<\/h3>\n

<\/a><\/p>\n

Step 2. <\/h3>\n

Click on the Toggle Button Icon from the Control as shown below:
\n<\/p>\n

\"Toggle<\/a>

Toggle Button<\/p><\/div>
\n<\/p>\n

Step 3. <\/h3>\n

Now Double Click on that Button
\n
\n

\"Toggle<\/a>

Toggle Button<\/p><\/div>
\n<\/p>\n

Step 4. <\/h3>\n

Here you can write your Code.
\n
\n

\"Toggle<\/a>

Toggle Button VBE Code<\/p><\/div>
\n<\/p>\n

Example: <\/h3>\n

I am going to explain you by giving two examples, how we can use this button in real time applications.
\n<\/p>\n

1. Hiding\/un-hiding Row or Columns by Toggle Button: <\/h3>\n

In this case, Clicking on the same button, each time different action will be performed, it means, once it will hide it and next time it will un-hide it.
\n<\/p>\n

\nPrivate Sub ToggleButton1_Click()\n'For hiding and un-hiding Columns\n  Columns(\"C:F\").Hidden = Not Columns(\"C:F\").Hidden\n'For hiding and un-hiding Rows\n  Rows(\"1:2\").Hidden = Not Rows(\"1:2\").Hidden\nEnd Sub\n<\/code><\/pre>\n

<\/p>\n

2. Sorting in Ascending and Descending Order by Using Toggle Button: <\/h3>\n

i) Add the Code of sorting in Ascending and Descending in a Regular Module in VBE of your Workbook<\/p>\n

<\/p>\n

To get the Code for Sorting in Ascending or Descending<\/h3>\n

<\/a><\/p>\n

ii) Paste the below code in the VBE of the Worksheet where you have Put your button:<\/p>\n

\n\nPrivate Sub ToggleButton1_Click()\n\t\n\tIf ToggleButton1.Value = True Then\n\t\tCall Sort_Ascending\n\tElse\n\t\tCall Sort_Descending\n\tEnd If\n\t\nEnd Sub\n\n<\/code><\/pre>\n

<\/p>\n

To Know About Spin Button in Excel Click Here<\/h3>\n

<\/a><\/p>\n

<\/p>\n\n\n
\n 
\nTo Check out more Excel Macro Tutorials, visit Excel Macro Tutorial<\/a><\/strong>
\n\n<\/td>\n<\/tr>\n<\/table>\n<\/span>","protected":false},"excerpt":{"rendered":"

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. […]<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1675],"tags":[],"class_list":["post-12125","post","type-post","status-publish","format-standard","hentry","category-excel-macro-for-beginners"],"yoast_head":"\nExcel Macro Tutorial : Toggle Button in Excel - Let's excel in Excel<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Excel Macro Tutorial : Toggle Button in Excel\" \/>\n<meta property=\"og:description\" content=\"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. […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/\" \/>\n<meta property=\"og:site_name\" content=\"Let's excel in Excel\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:author\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:published_time\" content=\"2012-02-09T18:01:44+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/learnexcelmacro.com\/wp\/wp-content\/uploads\/sites\/11\/2012\/02\/Toggle_Button_1.jpg\" \/>\n<meta name=\"author\" content=\"Vishwamitra Mishra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/www.twitter.com\/learnexcelmacro\" \/>\n<meta name=\"twitter:site\" content=\"@learnexcelmacro\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vishwamitra Mishra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/\"},\"author\":{\"name\":\"Vishwamitra Mishra\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"headline\":\"Excel Macro Tutorial : Toggle Button in Excel\",\"datePublished\":\"2012-02-09T18:01:44+00:00\",\"dateModified\":\"2012-02-09T18:01:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/\"},\"wordCount\":271,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"image\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/02\/Toggle_Button_1.jpg\",\"articleSection\":[\"Excel Macro Tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/\",\"name\":\"Excel Macro Tutorial : Toggle Button in Excel - Let's excel in Excel\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/02\/Toggle_Button_1.jpg\",\"datePublished\":\"2012-02-09T18:01:44+00:00\",\"dateModified\":\"2012-02-09T18:01:44+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#primaryimage\",\"url\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/02\/Toggle_Button_1.jpg\",\"contentUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/02\/Toggle_Button_1.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/vmlogger.com\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel Macro Tutorial\",\"item\":\"https:\/\/vmlogger.com\/excel\/excel-macro-for-beginners\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Excel Macro Tutorial : Toggle Button in Excel\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\",\"url\":\"https:\/\/vmlogger.com\/excel\/\",\"name\":\"Let's excel in Excel\",\"description\":\"Let's share knowledge\",\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/vmlogger.com\/excel\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\",\"name\":\"Vishwamitra Mishra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"contentUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"width\":528,\"height\":560,\"caption\":\"Vishwamitra Mishra\"},\"logo\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\"},\"description\":\"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.\",\"sameAs\":[\"http:\/\/www.learnexcelmacro.com\",\"http:\/\/www.facebook.com\/vmlogger\",\"https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro\",\"https:\/\/www.youtube.com\/c\/VMLogger\"],\"url\":\"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Excel Macro Tutorial : Toggle Button in Excel - Let's excel in Excel","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/","og_locale":"en_US","og_type":"article","og_title":"Excel Macro Tutorial : Toggle Button in Excel","og_description":"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. […]","og_url":"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/","og_site_name":"Let's excel in Excel","article_publisher":"http:\/\/www.facebook.com\/vmlogger","article_author":"http:\/\/www.facebook.com\/vmlogger","article_published_time":"2012-02-09T18:01:44+00:00","og_image":[{"url":"http:\/\/learnexcelmacro.com\/wp\/wp-content\/uploads\/sites\/11\/2012\/02\/Toggle_Button_1.jpg"}],"author":"Vishwamitra Mishra","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/www.twitter.com\/learnexcelmacro","twitter_site":"@learnexcelmacro","twitter_misc":{"Written by":"Vishwamitra Mishra","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#article","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/"},"author":{"name":"Vishwamitra Mishra","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"headline":"Excel Macro Tutorial : Toggle Button in Excel","datePublished":"2012-02-09T18:01:44+00:00","dateModified":"2012-02-09T18:01:44+00:00","mainEntityOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/"},"wordCount":271,"commentCount":1,"publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"image":{"@id":"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#primaryimage"},"thumbnailUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/02\/Toggle_Button_1.jpg","articleSection":["Excel Macro Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/","url":"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/","name":"Excel Macro Tutorial : Toggle Button in Excel - Let's excel in Excel","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/#website"},"primaryImageOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#primaryimage"},"image":{"@id":"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#primaryimage"},"thumbnailUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/02\/Toggle_Button_1.jpg","datePublished":"2012-02-09T18:01:44+00:00","dateModified":"2012-02-09T18:01:44+00:00","breadcrumb":{"@id":"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#primaryimage","url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/02\/Toggle_Button_1.jpg","contentUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/02\/Toggle_Button_1.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/vmlogger.com\/excel\/2012\/02\/toggle-button-in-excel\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vmlogger.com\/excel\/"},{"@type":"ListItem","position":2,"name":"Excel Macro Tutorial","item":"https:\/\/vmlogger.com\/excel\/excel-macro-for-beginners\/"},{"@type":"ListItem","position":3,"name":"Excel Macro Tutorial : Toggle Button in Excel"}]},{"@type":"WebSite","@id":"https:\/\/vmlogger.com\/excel\/#website","url":"https:\/\/vmlogger.com\/excel\/","name":"Let's excel in Excel","description":"Let's share knowledge","publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vmlogger.com\/excel\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5","name":"Vishwamitra Mishra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/","url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","contentUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","width":528,"height":560,"caption":"Vishwamitra Mishra"},"logo":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/"},"description":"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.","sameAs":["http:\/\/www.learnexcelmacro.com","http:\/\/www.facebook.com\/vmlogger","https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro","https:\/\/www.youtube.com\/c\/VMLogger"],"url":"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/"}]}},"_links":{"self":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/12125"}],"collection":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/users\/45"}],"replies":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/comments?post=12125"}],"version-history":[{"count":0,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/12125\/revisions"}],"wp:attachment":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/media?parent=12125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/categories?post=12125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/tags?post=12125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}