Create Toggle Buttons that change color and change other cell values

epmd

New Member
Joined
Jul 20, 2021
Messages
8
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello all, I am new to VBA and am trying to figure out how to create buttons that perform certain functions.
I am creating a product information page that provides specs for a given product. By default, all information should display in English units. In addition, the button "English" under Measurements in column E should automatically be gray (White, Background 1, Darker 35%/ Hex: #A6A6A6), inner bevel with white text. If the user clicks Metric (column F), then the following actions should happen:

1637178831942.png

  1. Format of the English and Metric buttons should swap.
  2. Calculations for the dimensions in columns B - D should be converted to metric units.
  3. Text in column A should change to represent metric units.
  4. If the user clicks the English button again, it should revert back to the original state. However, clicking the already depressed button should not result in any additional actions.
For reference, the cell range pasted above is A10 to F13. Buttons are in E12 and F12. The Metric button is outer bevel with black text on a gold button (Gold, Accent 4, Lighter 40%/ Hex: #FFD966).

I appreciate any assistance with this!
 

Attachments

  • 1637178734225.png
    1637178734225.png
    14.2 KB · Views: 29

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I've created an Excel File with VBA (<- download left), is this what you need?


View attachment 51674
Pete, I downloaded your file, and everything worked perfectly. However, when I tried to adapt the code for my workbook, things went haywire and I was unable to use Toggle buttons. When I tried to add the macro for the convert functions to the existing "buttons" I had created, I got an "undefined" error. So I went to the developer tab, clicked to Insert Toggle Button, but then it tries to attach an "EMBED..." function, which creates a fatal Excel error. Not sure what I'm doing wrong in adapting this.
 
Upvote 0
Pete, I downloaded your file, and everything worked perfectly. However, when I tried to adapt the code for my workbook, things went haywire and I was unable to use Toggle buttons. When I tried to add the macro for the convert functions to the existing "buttons" I had created, I got an "undefined" error. So I went to the developer tab, clicked to Insert Toggle Button, but then it tries to attach an "EMBED..." function, which creates a fatal Excel error. Not sure what I'm doing wrong in adapting this.
Hi @epmd and sorry for the late response.
Do you still need help with the VBA code?
Please let me know here.
 
Upvote 0
Hi @epmd and sorry for the late response.
Do you still need help with the VBA code?
Please let me know here.
Hi @PeteWright, yes, I still need some help with this. I wasn't able to figure out the issue with why I couldn't adapt your code to my spreadsheets. Please note that I am using Excel 365.

I have tried it using button shapes with assigned macros, and I get a VB error, Run-time error 9 when I assign the functions to the appropriate buttons.

1640794293475.png

The Debugger gives an error with this line:
If ThisWorkbook.Sheets("Sheet4").Toggle0.Value = True And ThisWorkbook.Sheets("Sheet4").Toggle1.Value = False Then


I have copied the mini-sheet below from my original workbook. I modified the VBA code to reflect the actual sheet and cell locations in my workbook, but when I clicked to Insert Toggle Button instead of assigning a macro to a button shape, Excel tries to attach an "EMBED..." function, which creates a fatal error.

ConvertTest.xlsm
ABCDEF
11Product InformationUnit* (Net - oz.)Inner PackCase PackMeasurements
12 Weight12 10.987
13Dimensions (L X W X H) (in.)2.1875 x 2.1875 x 8.68759.25 x 7 x 9.313EnglishMetric
14Volume (cu.ft.)0.0241 0.3490
User Interface by SKU
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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