Form Controls
What Are Form Controls?
Form Controls are objects which you can place onto an Excel Worksheet which give you the functionality to interact with your models data.
You can use these controls on worksheets to help select data. For example, drop-down boxes, list boxes, spinners, and scroll bars are useful for selecting items from a list. Option Buttons and Check Boxes allow selection of various options. Buttons allow execution of VBA code.
By adding a control to a worksheet and linking it to a cell, you can return a numeric value for the current position of the control. You can use that numeric value in conjunction with the Offset, Index or other worksheet functions to return values from lists.
Use below links to quickly learn about Form Controls:
- What are form controls & introduction
- Button Control
- Label Control
- Check box Control
- Option Button Control
- List box Control
- Combo box Control
- Spin Button Control
- Scroll bar Control
- Group box Controlg
- Using Form Controls – techniques & examples
- Other Controls in Excel
Where Are Form Controls?
Form Controls are located on the Developer Tab under Insert Form Control.
PS: If you do not have developer tab, learn how to enable it.
You will notice 2 types of Form Controls, being Form Controls and Active X controls.
This post will only be dealing with Form Controls. The Active X controls, similarities and differences will be discussed towards the end of the post.
How Do I Insert a Form Control
To Insert a Form Control goto the Form Control Menu and click on the Form Control you want to insert.
Now click on the worksheet in the location you want your form control.
Don’t worry about the location or size you can change those later.
What Are The Different Form Controls?
There are several types of Form Controls offering a range of interactivity from a simple display through to interactive controls which allow multiple selection or interactive selection of values.
Control Name | Description | Function |
Button | Push Button | Executes a macro |
Check Box | Allow selection of non-exclusive options | Multiple On/Off options |
Combo Box | Drop Down selection Box | Select items from a Drop down list |
Group Box | Layout element which groups common elements | Nil |
Label | A Text label | Can be static or linked to a cell |
List Box | Fixed selection box | Select items from a list |
Option Button | Allow selection of exclusive options | Exclusive Single On/Off option |
Scroll bar | Allow Horizontal or Vertical scrolling | Increases or decreases a cells value by a fixed amount |
Spin Button | Increment/decrement a value by a fixed amount | Increases or decreases a cells in steps by a fixed amount |
These are discussed individually below
Form Control Types
Button (Form Control)
The Button Form Control is as its name suggests simply a Button.
Pressing the Button allows execution of a macro.
The Button has no other controls.
Button Text
You can right click on the button and change the buttons Text (Edit Text) and enter the text you want displayed on the button.
The Button’s text can be linked to a cell, select the Button, In the formula Bar enter a link to a cell. eg: =$C$3 and accept. The Button’s text will now change as the contents of the cell C3 change.
You can change the Text Style including Font, Color and Text Direction using the Format Control (Ctrl 1) option.
Assign Macro
Right click on the Button and select Assign Macro
The Assign Macro dialog will pop up.
Select the macro you want to assign to the button.
Label (Form Control)
The Label Form Control is also as its name suggests simply a Label.
The Label will display text either fixed or from a linked cell
You can right click on the button and change the buttons text (Edit Text).
The Button’s text can be linked to a cell, select the Button, In the formula Bar enter a link to a cell
eg: =$C$3 and accept. The Button’s text will now change as the contents of the cell C3 change.
Unlike the Button you cannot change the Text Style, Font, Color or Text Direction.
Typically a label is put in front of another Control to explain or add a title to the control.
Labels would rarely be used on a Worksheet as a label as they have limited text format properties.
Users would be better served using either cell text or a Text Box where full text formatting is allowed.
Labels come into use when setting up custom Dialog Forms which are used by VBA applications for custom data entry or other uses.
Check Box (Form Control)
The Check Box form Control allows selection of a number of non-exclusive options.
That is any number of Check Box controls may be implemented and they independently be on or off and have no relationship to each other.
The Check Box Form Control returns the value indicating its status, either True (selected) or False (not selected), to a linked cell.
To link a Format Control to a cell, Right Click the Format Control and select Format Control…
Option Button (Form Control)
The Option Button form Control allows the selection of an exclusive option from a number of alternatives.
That is only one Option Button Form Control may be selected at a time, the remainder are automatically turned off.
The Option Button Form Control returns the value of the Option Button indicating its status to a linked cell.
In the Example above the Option Buttons are linked to cell E2.
You only need link one Option Button to cell E2, Excel automatically links the remaining option buttons to teh same cell.
Selecting a Different Option Button automatically deselelects the other Option Buttons and changes the linked cells value
List Box (Form Control)
The List box allows the selection of one or more items from a list.
The list is sourced from a Range of cells in the above case it was F2:F17.
The List Form Control returns an Index Number or position of the selected item to the Cell Link, 5 in the example above.
The Input Range and Cell Link are setup by Right Clicking the control and select Format Control…
The Number of items visible in the list box is determined by the size of the list box
If there are more items than will fit in the list box then a scroll bar is automatically added to the list box to enable there selection.
Combo Box (Form Control)
The Combo Box allows the selection of one or more items from a drop down list.
The Combo Box use is similar to the list box except that it has a drop down selection list instead of a fixed length selection list.
The list is sourced from a Range of cells in the example below it was F2:F17.
The List Form Control returns an Index Number or position of the selected item to the Cell Link B10, 9 in the example below.
The Input Range, Cell Link and size of the Drtop Down Box are setup by Right Clicking the control and select Format Control…
Spin Button (Form Control)
The Spin Button is a simple toggle button that allows the increase or decrease of a linked cells value by a certain pre-defined amount.
The Cell Link and Lower, Upper Limits and Step Size parameters are setup by Right Clicking the control and select Format Control…
The Lower, Upper Limits and Step Size must be Integers. If you want to increase a cell by fractional amounts you will need to for example set the range from 0 to 1000 in steps of 1 and then devide the linked cell by 10 which will give a Range of 0 to 100 in steps of 0.1
Scroll Bar (Form Control)
The Scroll Bar Form Control often referred to as a Slider is a simple linear slider that allows the increase or decrease of a linked cells value by sliding a bar either left/right or up/down.
Scroll Bars can be placed either Horizontally or Vertically by dragging the corner.
Scroll bars are incremented by the Step Size by clicking the ends of the bars or dragging the slider or by a Page Jump Size by using Page up[/down or clicking either side of the slider bar.
The Cell Link, Lower, Upper Limits, Incremental Change and Page Change parameters are setup by Right Clicking the control and select Format Control…
The Lower, Upper Limits, Incremental Change and Page Change must be Integers. If you want to increase a cell by fractional amounts you will need to for example set the range from 0 to 1000 in steps of 1 and then devide the linked cell by 10 which will give a Range of 0 to 100 in steps of 0.1
Group Box (Form Control)
The Group Box Form Control isn’t really a Form Control at all, as it allows no interactivity.
What it is used for is grouping similar controls so that functional groups of controls can be maintained and the users flow is directed around a form.
Using the Form Controls
General Use
The use of the information from a form control is limited by your imagination.
Typical uses are
- Selecting items for a chart
- Selecting data sets
- Moving data sets
- Adjusting values in a model
As described in each of the above Form Controls is that the Form Controls do not return a value directly from a list, they all return either a number or an index number relative to the position of the item in a list.
Examples of all the Form Controls and examples of their use can be found in the attached file:
Excel 2003 Examples or Excel 2007+ Examples
or
Have a browse through the dashboards presented during Dashboard Week
or
For some Extreme Examples of Spreadsheet Interactivity using Form Controls and a little bit of VBA code:
Running Macros
Apart from the Button Form Control whose only purpose is to Run Macro’s, all Form Controls can be linked to a Macro.
This is done by Right Clicking on the Form Control and selecting Assign Macro.
It is worth noting that the macro is only executed after the control is released.
EG: If you have a macro linked to a Spin Button, If the Spin Button is held down and hence repeatedly increments its value, the macro will only be executed after the control is released.
Moving and Resizing Form Controls
You can move and resize form controls as with all other worksheet Objects.
Select the form control by right clicking on it
Use the handles to resize or drag the edges to move the controls
Hint: You can use Alt while dragging or resizing to snap the control to cell boundaries.
3D, Printing & Locking Form Controls
You can lock Form Controls as well as enable them to be printed or not
Right Clicking the control and select Format Control…
Use the Size, Protection and Properties Tabs as required.
The 3D option enables a 3D version of the Control instead of a flat control, which can add a bit of sparkle in some instances.
Limitations of Form Controls
Form controls offer a limited set of functions but do those functions very well.
Limitations are Form Controls:
- Form Controls can only increase or decrease by integer numbers
- Form Controls only return the index of an item in a list
- Form Controls have limited format properties (Font, Color etc)
What are the Active X Controls
Active X controls are like Form Controls on Steroids in that they have a much wider range of properties than Form Controls.
They also have much better ties to VBA in terms of programmability and have a number of events that can be accessed programmatically.
The main limitation of Active X controls are that they use a Microsft Active X component. This means that if you are sharing your workbook with an Apple Mac user using Excel for Mac these functions wont be available as Active X isn’t avilable on that Platform.
Workbooks with Form Controls will happily work on a an Apple Mac.
Other Controls Available in Excel
A number of other Excel objects can be used to add interactivity to your worksheets.
Shapes
These include:
- Shapes
- Charts
- Text Boxes
- Word Art
All these can have macro’s linked to them which effectively act the same as a Button Form Control without the moving button effect.
A stunning example of using Text Boxes was recently posted at: The Grammy Bump Chart
Where the Artists Stats Box (Top Left of Chart) is using several Text Boxes linked to cells to show the Selected Artsists Statistics.
HyperLinks
Inserting Hyperlinks at stratgic locations throughout worksheets provides a great way to simplify navigation around pages and between pages
Other Links
Where have you used Form Controls ?
Where have you used Form Controls?
Let us know in the comments below:
56 Responses to “Creating in-cell bar charts / histograms in excel”
Ay jhakkas!!!
Man, you're on a roll. A true-blue Excel innovator. What you're writing makes me think - why didn't anyone else think of this before?
Now that I've showered all the praises on you, it won't hurt to have a few comments on my blaag 😉
PS. I meant the innovator part.
@Amit ... thanks, I was also curious why this one was not explored, but again, I havent really searched a lot to ensure that I am posting the same ideas again. My intent is to make few people to benefit from this, if that happens I would be happy...
btw, posted a comment on your blaag... hope you are happy now 😀
Don't worry about repeating the ideas in the online world. As long as you are not copying it off anyone else and it is helpful for the readers, it's fine.
PS. the comment does not count.
The idea actually is not a new one :).
Check out MicroCharts
http://www.bonavistasystems.com/
to see how far you can get with font based in-cell charting
[...] can never get tired of in-cell charts, whenever I get sometime, I try to experiment something on them. Here is an idea to design true [...]
[...] Since we can insert any character in to a cell using formula, by installing a custom bar chart / pie font in our computer we can create incell graphs in excel with ease. Click here to see example pie chart, line chart. [...]
Where is the file? I can't seem to locate it. I want to donwload it. Thanks Chandoo!
Found it.
Great job, Chandoo. Love the site - and the fact that you provide downloads to help us (me) learn your secrets faster. I downloaded the font but can't figure out how to add it to my font library... Any hints? Thanks! Keep up the fantastic work.
@Mahqooi: Thank you and welcome to PHD 🙂
This is how you can install a font in a windows machine:
unzip the font files (if needed)
select and copy the font file to clip board by pressing ctrl+c
go to control panel > fonts
paste the file by pressing ctrl +v
repeat this procedure for other font files if any
if you are using mac, just right click on the font file and select install option.
let me know if you have some issues with this.
Hi Chandoo,
is there any mirrors for the bargraph font?
it seems that fontstruct.com is down for maintenance.
thanks!
@Cybsych: I am not sure if they have any mirrors. I will look in to my backup to see if a copy of the font can be located and ping you back. Thanks.
hi Chandoo, fontstruct is back online 😉
BTW, I am wondering about this in-cell chart.
How do I apply an automated conditional formatting to only a bar/point?
For example, the first image in this post, whereby RED = highest, BLUE=lowest.
Chandoo,
I guess this bars only work with positive numbers? so if you a list of costs per month, but one month you have negative cost meaning income due to let's say vendor credits. This incell bar could despict the month with a negative digit. or could it?
hi Chandoo, guess that you missed out my query 😀
is there a way to highlight the MAX and MIN bar based on the actual data (not the normalized)?
@Pedro, for that you need to have another set of characters (may be A-J for 0-9 and K-S for -1 to -9 and then use them to show the bars. It is a bit tricky, but achievable.
@Cybpsych: The highlighting was done manually (As you can see, there is probably no easy way to highlight / change colors of a portion of cell using Conditional formatting etc.). I am sorry, but you need to use someother sparkline technique to achieve this (or, write your own macro)
http://chandoo.org/wp/2008/09/05/microcharting-excel-howto/
thanks chandoo!
I love this simple and quick way of visualization results. I would like to learn more about normalizing values (i.e. the use of linear normalization). Can someone kindly point me in a good direction for this beginner? Much thanks to everyone (especially Chandoo) for the wealth of information provided. Long live the internet age!
@Jason: you can use simple excel formulas to normalize a set of values. If the list of values is in say a1: a10 and you want them to be normalized from 1 to 100, you can do that with a formula like: =A1/max($A$1:$A$10) * 100. Also, you can use the RANK formula to calculate the percentile of any value in the list.
[...] Bar | Sparklines | Pie charts | Bullet Graphs | w/ Conditional [...]
Nifty way to normalize the data....I'll have to take that into account when working with my charts.
One thing I'd like to add, you can eliminate the need for custom fonts with the bar charts by using a REPT function and using a small "g" set to the Webdings font. It's more likely anybody opening the file will have access to that font than the custom one you've provided. (More portability is a good thing 🙂 )
Portability is great.
I don't quite see how the REPT formula and the webding fonts can combine to solve the portability issue.
Mind you, i see that +REPT("g",1) will give you a bar, but we would need several bars of unequal lenght.
Can you elaborate?
Thank you
@Matt: I almost forgot about this comment. Thanks to Pedro for the bump.
As he points, portability is a good idea, but we will not be able to get bars of variable height using webdings font.
We can ofcourse use that along with text rotation and char(10) to create a pseudo incell bars. Here is a tutorial: http://chandoo.org/wp/2008/07/15/incell-bar-charts-revisited/
@Chandoo: Yep, that's exactly what I meant, use your text rotation and char(10) trick with REPT("G",) (then set the font to Webdings) to get your string of bars with variable height.
@Pedro: REPT("g",1) will give you one "g" (or in Webdings a bar of 1 height).
REPT("g",B2) will repeat for the value in B2... 🙂 Use that with Chandoo's take on linear normalizing, and yer all set.
Wingdings with an "n" character would be even more portable, but just doesn't look quite as cool...but pretty much everybody has that font, so it'd be portable.
You may have to adjust the font size in order to get all the bars to show correctly, perhaps some sizing of the row heights as well...
You can fake an incell line chart by using:
REPT(" ",B2-1)&REPT("n",B2)
where B2 is the value in the cell you want as a data point.
Wow, the formatting was horrid, let's elaborate a bit more...
REPT("",-1)&REPT("n",) - would give you a line graph, where could be a reference to each cell you'd like as a data point.
REPT just repeats a text string a number of times, it can be either a hard number (like Pedro's example), or a reference to a value in another cell (more handy). I believe Webdings is a common font in the MS Office suites I'm familiar with (2000 thru 2003), but I'm not sure of 2007's suite.
@Matt A: I am sorry for the formatting mishap. I am afraid of using too many plug ins, but I guess a simple HTML based comment box seems like a good idea now that lot more commenters are typing formulas and vba code in the comment box.
Coming to the formula.. thanks for sharing it. And yes, you are right, webdings is common to Office 2007 too. But even better solution would be to use good old pipe | symbol. When the font is Arial, the pipe character spacing looks optimum and subtle enough to look like an incell histogram / column chart.
After some searching through the character maps in Arial I noticed that there's a box symbol --> ? (created by holding ALT then typing 5595 on the numpad) that would work perfectly as another character to use for column charts. It looks just like the Webdings "g" character.
Is there a way to change the colour of the bars based upon the data. eg. 1-5 = red, 6-7 = amber, 8-10 = Green
@Ben... you can change the color of all bars in a cell using conditional formatting. But selectively changing color of bars inside cell is not possible unless you do it manually or through VBA.
[...] Creating in-cell bar charts / histograms in excel @ Pointy Haired Dilbert Filed under: Stuff [...]
Is this work only for the numbers or will it work for % data also. I tried to do the same for % data, but i didnt get. Pls let me know the formula for % data.
[...] trick is to use Incell Charts. [...]
Hello Chandoo,
I really like this, but I have Office for Mac 2011 and for the life of me I cannot figure out how to see the bargraph as an available font.
I have followed all the instructions for adding a font, but it does not appear. Do you have any suggestions?
Thanks
prb
Thanks. This one was cool and helpful. Can we experiment the same with "in cell" line graph as well? 🙂
Chandoo,
How do you "manually" change the color of the last bar in the series?
Lawrence
@Lawrence
Select the chart
Select the series
Select the last point/column of the series
Ctrl 1 or right click Format Point
Select a color
Hui,
Thanks!
I should have been more descriptive. What I meant to ask was about the in-cell bar graph created with the REPT function described above. How do I get the last REPT (the last bar) to be a different color than the rest?
Lawrence
@Lawrence
You cannot change colors in a cell using formula
You can use either VBA code or do it manually
Select the cell
Copy and paste it as values
Edit the cell F2
using the arrows move to the character you want to color
Shift and select the cell by arrow keying over it
with the characyer selected
Ctrl 1 (Format Cells)
Change the Font Color to suit
It won't be a color change per se...but you can set an IF statement in your REPT formulas for different characters to show as the bars. The characters "c" and "g" in Webdings are both boxes, one is a solid block, the other an outline.
For example, say I wanted to highlight the highest bar in my REPT formulas...my formula to translate the numeric cells A2:A15 to characters would be:
IF(A7=MAX($A$2:$A15),REPT("c",B7),REPT("g",B7))
so if the cell I'm checking (here it happened to be A7), is the highest number...its bar would display differently further along down in the concatenations...
@Hui...THANKS!
@ Matt A... Very cool idea. What formatting do you recommend for the cell? The Webdings "c" hollow box is very faded and hard to read even if bolded and bigger font size is used. If I could just punch it up a bit it would be perfect with 5 "c" columns followed by a single solid "g" column...as in showing the trend in the trailing 6 months of data.
Lawrence
@ Lawrence
Good question...lately I've been using ? (which you get from holding ALT then typing 5595 on the numeric keypad) for most of my bars. Unfortunately the character map doesn't lead me to a differently "shaded" box of the same size. Reason I use this nowadays...it's part of arial font...just a special char map character I can rapidly input w/o any formatting nonsense.
I'll check to see if I can replicate another box of same size that may have different shading using the same method...no luck as of yet.
I've just built the in cell bargraph and was trying to create a pop up window which would display the Monthly Sales for Last 12 months when they click on any of the bargraph cells
[...] Reference: http://chandoo.org/wp/2008/05/13/creating-in-cell-bar-charts-histograms-in-excel/ Like this:LikeBe the first to like this. [...]
[...] To quickly insert an in cell micro-chart, use REPT() function… Get Full Tip [...]
Hi, there is a problem with the Bargraph font. On my win7 machine it works perfectly but when I try to install it on my boss's mac it returns an error called " 'Name' Table Structure"
I tried to install on two different macs and the same error resulted. As a result the font does not show up as an option in any program.
Just an FYI. I don't use macs but I know some people do.
Whats up! I just wish to give a huge thumbs up for the good info you might have right here on this post. I can be coming back to your weblog for extra soon.
[...] like .docx, .htaccess etc.) 43. To quickly insert an in cell micro-chart, use REPT() function… Get Full Tip 44. COUNT() only counts number of cells with numbers in them, if you want to count number of cells [...]
Thanks Chandoo for the font!! It works great once installed on my machine, but is there any way (besides printing and scanning the doc) that I can get the graphs to show up on other peoples' machines without going through the font install process? My file has to be sent out to clients that don't have that font installed.
Sarah, Excel doesn't allow embedding of fonts (aside from a workaround using a macro). The font will need to be sent to all who want to view the file. I went through the same question with my boss. I ultimately just installed the font on her computer.
If the data is only to be viewed, and not modified, moved, etc. you can save the file as a pdf. The font can be viewed that way.
Hello every one there is a problem I need auto update summary formula from other sheets data pick please give me sample file and also auto up grate summary sheet format.................
@Joesali
I'd suggest asking this type of question at the Chandoo.org Forums
I'd suggest uploading a sample file also
Hi chandu,
Apart from excel, i need the formula to find bar graph height dynamically when using with log scale, for example for linear graph i would take the maximum value to height of the panel as
(value divided by maxvalue) * height.
Now , i am using a logarithimic graph can you tell me the right formula which fits perfectly.
Thanks in advance
Nice info... Thanks... very hepfull... 🙂
The font does not seem to be available at fontshop. Is there somewhere else to download the bargraph font?
@Amber
Try doing a Google search for Bargraph Font
it returns several possibilities
Is there a way to do this without using bar graph font? We have a financial report to be published to stakeholders and they will not have this font installed, so probably will not be able to view the bar chart as well.