Excel worksheet interactivity with ActiveX controls

Using the Control Toolbox we can create interactive worksheets without any VBA whatsoever.

Commonly called ActiveX controls, one application for them is to link them to worksheet cells. This allows you to put controls on your form, capture user input (typically in a hidden section of the worksheet), and make worksheet-level calculations. Here are short descriptions of many of the available ActiveX controls.

Download sample workbook

Check box control

The check box control returns TRUE when checked, and FALSE when not. When linked to a cell, the cell will display either TRUE or FALSE accordingly.

Combo box control

The combo box control can be made to read a list of values from the worksheet to populate the combo box, and read the user selection or entry back to the worksheet. Unfortunately you can't restrict choices to just those found on the list (as you can in Access, or with Excel's Data Validation feature).

List box control

Like the combo box control, the list box control can read a set of values from the worksheet to populate itself, and write the selection to the worksheet. But it does not allow selections or entries that are not on the list. So it's ideal when the user must select something and should not be allowed to select anything else.

Option button control

Like check boxes, option buttons return TRUE or FALSE to the worksheet. You can also see a toggle button in the screenshot above, which we'll explain below.

Scroll bar control

The scroll bar control can be set to minimum and maximum values, which are cycled through in the linked cell when the scroll bar is moved. Set these to the range needed for your particular application.

Spin button control

The spin button control is similar to the scroll bar, except you click a button to change the linked cell, instead of moving a button across a scroll bar.

Text box control

The text box control takes it input and places it into the linked cell.

Toggle button control

The toggle button has two states: up or down. When depressed (down), the value returned to the linked cell is TRUE. When the button is up, the value returned to the linked cell is FALSE. I used a toggle button with the option button because otherwise there's no way to reset the option button; you can only click it once. The toggle button changes the value of the linked cell to FALSE, which effectively clears the option button control.

Sample controls form

To demonstrate how you might combine these controls together into a worksheet "form", I created a sample form. All I did was use the Drawing toolbar to draw a rectangle on the worksheet. After adding a shadow (Shadow Style 6, if you must know), I added some linked controls on top of it, and moved them to the top of the display order. To do that, right-click each object and choose Order from the context menu. Then Ctrl+click all of the controls and group them (on the Drawing toolbar, go to Draw » Group). Now you can drag the whole thing around as a grouped set of controls.

All of the controls on the sample form are linked to the same cells as the other controls, so you can change values on the form and watch the other controls adjust themselves!

Debra Dalgleish wrote about combo boxes on her blog (see 3 Types of Excel Drop Down Lists Compared ), and Jan Karel Pieterse has an article about ActiveX controls as well. Do you know of any other good articles?

Download sample workbook

Related Articles:

About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »

Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button

comment bubble 11 Comments:

  1. Danièle writes:

    Great start into those control tools. Many thanks!
    I was unable to open though the zipped folder getting a 'corrupt file message".
    I tried several times, with no luck.
    Thanks again!
    Danièle

  2. Phil writes:

    Hi JP,

    interesting article and good introduction into the usage of form controls / Active-X-controls to "manipulate" key cells of your spreadsheets.

    I use them quite a lot and it's very interesting what you can do with them. What I would like to add, if you want to know how these controls work, you have to enable the controls toolbox and there activate the edit mode. Then right click the controls and select properties to see to which cells these controls refer.

    My general advice for beginners in this field of user interaction would be to not use the Active-X-controls but the "normal" form controls because most of the time, they will do what you want and are much easier to adjust (my humble opinion) by simply right-click them and select format control.

    Oh, and yes, you asked for other good posts covering this topic. I personally like Chandoo's post on "comparison charts w/ form controls ( http://chandoo.org/wp/2009/03/12/comparison-charts-1/ )"

  3. Lee E. writes:

    I also was not able to unzip the sample workbook. Unsuccessfully tried WinZip, 7-Zip, and WinRAR.

  4. chrisham writes:

    Lot of stuff to be learing here, thanks JP once again. Just a small clarification, I know you mentioned the Style 6 to get the shadow effect, but I am using Excel 2007 and I don't see anyway to get the Style 6 that you are refering here. Could please you explain how you got that Style 6 Shadow effect ?

    • JP writes:

      In 2003, on the Drawing toolbar, there's a Shadows button where you can apply different shadow styles to an object. Hovering over them tells you which number they are. I'm afraid I don't know how to duplicate this in 2007+.

  5. Lee E. writes:

    @JP…The new link in XLS format worked fine – thanks!

Comments on this article are closed. Why?

Site last updated: February 12, 2012