VBA Question on Option Box

easybpw

Active Member
Joined
Sep 30, 2003
Messages
437
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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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:
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,749
Members
448,989
Latest member
mariah3

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