Excel – Using Form Controls
Posted by excelmate
From time to time you may come across tick boxes, option buttons or similar on a worksheet. These seem to be little objects that appear to do some clever things in formulas or to objects on your worksheet such as charts. These are not as difficult to set up and use as you might think.
First of all, you need access to FORM CONTROLS.
Make sure your DEVELOPER tab is turned on (2013 – right click on the RIBBON and select CUSTOMIZE THE RIBBON and tick the DEVELOPER box/2007 – click the OFFICE button, then select EXCEL OPTIONS and tick the third box down – SHOW DEVELOPER TAB IN RIBBON).
From the DEVELOPER tab click on INSERT. This will show you all the available controls.
Make sure you choose from the top half i.e. FORM CONTROLS and not from ACTIVEX CONTROLS or you’ll be expected to start writing VBA code to make them work! If you want to, right click over the icons and select ADD GALLERY TO QUICK ACCESS TOOLBAR. This will then give you a shortcut to the controls.
Now you have access to the controls, let’s start using them.
The controls at your disposal are;
- Combo boxes
- Tick/check boxes
- Spin buttons
- List boxes
- Option buttons
- Group boxes
- Scroll bars
There are a few others there but the label option is pointless as you can use INSERT – TEXT BOX, and there are a few greyed out buttons too, that no one seems to know why they exist on the toolbar if they can’t be used.
So how do you use these FORM CONTROLS?
Click on the BUTTON icon then click and drag on the worksheet to draw your new button. Don’t worry if it’s not the right size you can always adjust it afterwards.
As soon as you draw the BUTTON a new window will appear prompting you to assign a macro to the BUTTON.
Select a MACRO from the list and click on OK. If you don’t know what macros are, then you won’t need any buttons.
Any BUTTON you add will be given a default name…Button1, Button2 etc. Once you’ve added your macro, edit the caption on the button to let users know what it does.
Click away from the button, and it is now active and ready to use. Just click the button to make it run the macro for you.
If you need to adjust the size of the button or change the caption hold down the CTRL button and click otherwise you’ll just run the macro. Make sure you release the CTRL button once you’ve clicked on it or you’ll create a duplicate if the mouse moves while the CTRL button is being held down.
Along with buttons, this is probably one of the more likely controls you are going to use. As with the BUTTON, click on the icon in the toolbar and draw it on your worksheet.
You can edit the caption and resize if necessary. However, a tick/check box is purely a visual object. By that I mean it does nothing by itself other than look pretty. In order to make it useful, you need to right click on it and select FORMAT CONTROL. All the usual formatting options exist and you can play with those to discover what they do. The important tab to look at is the CONTROL one.
Set the default value (read appearance) of the tick/check box. Mixed is an odd one…the box just appears filled in.
The most important bit here though is the CELL LINK. Select a cell that will contain the value associated with the choice made with the TICK/CHECK box. Ticked/checked is equal to TRUE, and un-ticked/unchecked is equal to FALSE.
It is the value in the selected CELL LINK that you then use in your formulas. The TICK/CHECK box is simply an interactive image. Without the CELL LINK, the TICK/CHECK box does absolutely nothing of use other than display a tick or no tick.
Setting these up is exactly the same as the TICK/CHECK box. Draw it, right click, and assign a CELL LINK. As you add more OPTION buttons they are all linked to the same cell. Depending on the OPTION button you select a different number will appear in the cell.
What if you want to create a set of separate OPTION buttons that are not linked to the first set?
This is where you have to use a GROUP BOX.
Draw a GROUP BOX, add some OPTION buttons inside it, select any one of the buttons, right click and assign a CELL LINK. All the other buttons within the group box will then link to the same cell. You will now have two independent sets of options to choose from.
Follow the same routine to set these up as above. The difference with these is that you need to have a set of source cells that contain information you want to see appear in the list. This is the INPUT RANGE on the CONTROL tab. Select a CELL LINK too. DROP DOWN LINES refers to the number of items to be displayed in the box. Beyond that scroll bars need to be used to see the rest of the items in the list.
When you use the COMBO BOX, the INPUT RANGE appears in the drop down, and when you make a selection from the list, the CELL LINK will display the position of the selected item as a number.
Usual set up…go to the CONTROL tab.
Set a current value, minimum and maximum values, as well as a value for incremental change i.e. each time someone uses the up or down button, how much does the value change by? Make sure you set a CELL LINK as with all the others.
Obviously, you can set any min/max and increment you want…entirely down to what you want to display.
Wheras the COMBO BOX gives you a drop down list, a LIST BOX is exactly what is says – a box that contains a list. So when you draw the box, make sure it is big enough to display at least part of your list. Scroll bars will appear if the list is longer than the box.
There are a few options in the CONTROL tab that we have not seen yet.
INPUT RANGE and CELL LINK are identical to the other controls but you have options relating to SELECTION TYPE. In reality, only the SINGLE option is viable. Although you can select multiple items in the list, the CELL LINK can only store one value. EXTEND allows you to click and drag across multiple items to select them, but again, same problem applies to the CELL LINK. To make use of MULTI and EXTEND options you need to apply some VBA coding.
Usual set up applies…SCROLL BARS can be vertical or horizontal. The settings for SCROLL BARS are identical to SPIN BUTTONS. Just go to the CONTROL tab and set everything there.
So setting all these controls is fairly simple. They all pretty much follow the same steps. The next step of course is using them in a useful way.
It is probably tempting once you know how to set these up in a worksheet to put as many FORM CONTROLS as is humanly possible into your work. However, be warned…the more controls you put in the more possible combinations you need to deal with.
Let’s take a simple example: you have two tick/check boxes and four option buttons in one group. Seems simple enough but what are all the possible choices that someone can make?
Looking at the table above, each TICK/CHECK box can be TRUE (T) or FALSE (F). We can choose only one option out of four. If an option button is selected then this is shown with a Y and N if not selected. What started as a good idea, quickly becomes a major problem, as you now have to write nested IF statements that can cope with any of the 16 possible outcomes. Imagine adding another option group or a combo box into the mix and how that might affect the total number of possible combinations! Unless you are very confident with creating long nested functions this is a non-starter. I’m not saying don’t do it….but think about what you need to do to manage it all in your spreadsheet. Here is a basic example of a nested IF statement to handle a single tick/check box and two option buttons…
Gives you an idea of what you are facing, the more controls you add.
So FORM CONTROLS are a great way to add some sort of clever interaction in a spreadsheet. They can help to show/hide information, perform calculations based on criteria or can help you build dynamic charts. All I’ll say is don’t get carried away as the number of possible outcomes increases very quickly with each additional control that you add, but certainly a set of tools worth taking a look at.
Posted on January 22, 2015, in General and tagged button, check box, combo box, form controls, group box, list box, msexcel, option button, scroll bar, spin button, tick box. Bookmark the permalink. Leave a comment.