VBA Question on Option Box

easybpw

Active Member
Joined
Sep 30, 2003
Messages
410
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Hello and thanks in advance for the help,

I know the code below works (all other aspects of my codes work) when I want to select male or female in an option box but I can't figure out how to change it when the option box has 4 different options. I have changed other parts of the code but the debugger stops here when I try and add additional options.

.Cells(iRow, 3) = IIf(frmForm.optFemale.Value = True, "Female", "Male")

I'm a very basic VBA guy so any help is appreciated.

Thanks!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
11,686
What are your 4 different options? The code above works for True/False. If the options are 0-3, then something like:

.Cells(iRow, 4) = Array("Option 0", "Option 1", "Option 2", "Option 3")(frmForm.optSomething.Value)

If your options are other numbers, it's easy enough to shift them to fit the array ranges. If your options are values, you can just send them directly to the cell:

.Cells(iRow, 4) = frmForm.optSomething.Value

Otherwise, you'd need some kind of lookup table.
 
Last edited:

Forum statistics

Threads
1,148,324
Messages
5,746,121
Members
423,993
Latest member
Vighper

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
Top