09-01 Add Group Box and Option Button form controls without VBA - YouTube

Channel: The Smart Method

[0]
For this lesson, you need to open the sample file: Mortgage Calculator-1, from your Sample Files folder.
[8]
In this lesson, we’re going to add some controls to a form.
[14]
Because form controls are a very advanced feature of Excel, Microsoft hides them from normal users.
[21]
You need to add a Developer tab, to the Ribbon, in order to reveal them.
[26]
The easiest way to do this is to right-click in a blank area of the Ribbon, and select: Customize the Ribbon, from the Shortcut menu.
[36]
And you can see that all of the main tabs are enabled on the Ribbon, except the Developer tab.
[43]
So I’ll check the Developer checkbox, and click: OK.
[47]
And you can see that a Developer tab has now appeared on the Ribbon.
[52]
I’m going to replace the Deposit textbox, in row 5, with a Group Box control and Option Button controls.
[62]
So I need a little more room on the form.
[65]
I’ll begin by deleting row 5.
[68]
And then, I’ll insert two rows, so that I’ve got four clear rows, between the Property Price and the Arrangement Fee.
[76]
And now, I’m going to add a Group Box control.
[80]
To do that, I’ll click my new Developer tab, on the Ribbon.
[84]
And in the Controls group, I’ll click: Insert.
[88]
And you can see that there are two sets of very similar controls: Form Controls and ActiveX Controls.
[97]
The Form Controls are designed to be used without any understanding of the Visual Basic for Applications
[105]
(or VBA) programming language.
[108]
While the ActiveX Controls are intended to be used as part of the Visual Basic programming environment.
[116]
Unless you have Visual Basic programming skills, you’ll probably not find a use for the ActiveX Controls.
[124]
You’re going to learn a little more about VBA’s relationship with Excel in Lesson 9-10.
[131]
So I’m going to choose a Group Box control, from the Form Controls section of this dialog.
[139]
I click on: Group Box, and then, I hold down the Alt key, on the keyboard.
[145]
By holding down the Alt key, the Group Box will snap to the corner of the cells that I draw the Group Box in.
[152]
You’ll see this happening now.
[154]
I’ll position the cursor close to the top-left corner of where I want my Group Box to be.
[160]
And then, click-and-drag.
[162]
And you can see that the Group Box is snapping to the corner of the cells.
[166]
And now, I’ll release the mouse button.
[169]
And I’ll give my Group Box a name.
[172]
To do that, I’ll click on Group Box 1, and I’ll change the caption of the Group Box, to: Deposit. And I’ll add a Colon.
[181]
So that you can see where we’re going with this Group Box, I’ll now place a graphic of the finished item,
[188]
next to the Group Box I’m building.
[191]
And you can see that my Group Box is going to contain six Option Button controls.
[197]
Allowing the user to select a deposit, from 5% to 30%, in increments of five percent.
[205]
So let’s now add those Option Button controls.
[209]
To do that, I click: Developer, on the Ribbon.
[212]
In the Controls group, it’s: Insert.
[215]
And from the Form Controls group, the Option Button control.
[220]
I click, and now, I’m going to draw an Option Button control, inside my Deposit Group Box.
[227]
Now, there’s a few important rules to remember, when you do this.
[230]
First of all, the border of the Option Button cannot cross the border of the Group Box.
[236]
If you do that, then the Option Button control won’t work properly.
[241]
Also, keep your Option Buttons small, because you don’t want them to overlap.
[246]
And it’s really important that you add them in the right sequence: 5% first, then 10%, then 15%.
[255]
You’re going to see why that’s important later, in this session.
[259]
So there’s my first Option Button.
[261]
And now, let’s add the others.
[263]
So: Option Button. Draw it alongside. That’s my second button.
[268]
Another Option Button. That’s the third one.
[272]
Another Option Button. There’s my fourth one.
[276]
Another Option Button. There’s Option Button number five.
[280]
And, finally, we’ll have Option Button number six.
[286]
Now, the Option Buttons don’t look very neat, at the moment.
[289]
But don’t worry about that. We’re going to automatically align them later.
[294]
Now, I’m going to add labels for my Option Buttons, from 5% to 30%.
[300]
And to do that, I need to double-right-click each Option Button.
[304]
So I’ll double-right-click the first Option Button, and type: 5%.
[310]
Double-right-click the second, and that’s: 10%.
[314]
Double-right-click the third. That’s: 15%.
[318]
Double-right-click the fourth one. That’s: 20%.
[322]
Double-right-click the fifth. That’s: 25%.
[327]
And double-right-click the last Option Button. That will be: 30%.
[333]
I’ve now added captions for all of my Option Buttons.
[337]
Now, I’m going to test the Option Buttons.
[340]
Because if any of them have overlapped the boundary of the Group Box, they won’t work properly.
[346]
To test them, I’ll click on: 5%.
[349]
And when I click on the 10% Option Button, the 5% button should extinguish. That’s worked.
[356]
That’s worked.
[358]
That’s worked.
[359]
That’s worked and so has the last one.
[362]
So all of my Option Buttons are working correctly.
[367]
Now, I want to space, size and align the Option Buttons.
[371]
Now, you could align them simply by double- right-clicking an Option Button.
[375]
And then, use the Arrow keys, on the keyboard, to move them around.
[380]
But you won’t be able to perfectly align them, in this way.
[384]
To give your form the most professional appearance, you’ll want to do this automatically.
[389]
Before I automatically align and space the Option Buttons, first, I’m going to make sure that they’re all the same size.
[397]
To do that, I’ll right-click on one of the Option Buttons, and select: Format Control, from the Shortcut menu.
[404]
And then, I’ll click the Size tab.
[407]
And I can see that the size of this Option Button is 0.24 high and 0.33 inches wide.
[417]
On your system, you may see centimeters here, instead, depending upon your Locale settings.
[423]
So I’ll make a careful note of those two numbers.
[427]
And then, I’m going to automatically size all of the other Option Buttons, so that they’re the same.
[434]
To do that, I’ll first click: Cancel, to remove the Format Control dialog.
[439]
Then, I’ll hold down the Ctrl key, on the keyboard, and I’ll right-click on each of the Option Buttons in turn.
[446]
Now, for the sizing. I’ll right-click, on any of the selected Option Buttons, select: Format Object, click on the Size tab.
[455]
And for the height, I’ll type in that value of 0.24 that I made a note of earlier.
[461]
And you can see that, in every case, the widths are already 0.33 inches.
[467]
When I click: OK, all of the Option Buttons are sized to be exactly the same.
[473]
Now, I want to align the tops of my Option Buttons.
[477]
To do that, I’ll use the Format tab, in the Drawing Tools group of the Ribbon.
[482]
Then, I’ll click the Align option, and: Align Top.
[487]
And the tops of all of the Option Buttons are now perfectly aligned.
[492]
Now, I can see that the text of the 30% Option Button is over-spilling the side of the Group Box control.
[499]
So I’m going to move that in a little, before progressing.
[502]
I’ll click away from the Group Box control, then double-right-click on the 30% Option Button.
[509]
And use the Left Arrow, on the keyboard, just to move that in from the border.
[514]
Now, I’m going to select all of my Option Buttons, again.
[518]
So I’ll hold down Ctrl, on the keyboard, and right-click on each of the other buttons in turn.
[523]
And now, I’m going to space them perfectly, so that the gap between each Option Button is exactly the same.
[531]
To do that, it’s the Drawing Tools group, and: Format, on the Ribbon.
[535]
And in the Arrange group: Align, and then: Distribute Horizontally.
[542]
And now, the Option Buttons are perfectly spaced and perfectly aligned.
[547]
That may have seemed like rather a lot of work.
[550]
But your Form Controls will look far more professional, if you automatically align them, rather than align them manually.
[559]
Now, I’m going to add a very similar Group Box and Option Buttons, to replace the existing Term box.
[566]
First, I need to make a lot more space.
[569]
So I’ll delete row 12, and then, I’ll insert three rows, to replace it.
[578]
I now have five clear rows, between the Interest box and the Amount Financed box.
[584]
It might be useful, at this stage, to show you how the Term Group Box and Option Buttons are going to look.
[591]
So I’ll paste in a graphic.
[594]
You can see that I’m going to add a Group Box control, with six Option Button controls inside it.
[601]
So let’s begin with the Group Box control.
[604]
That’s: Developer, on the Ribbon.
[606]
In the Controls group: Insert.
[608]
And in the Form Controls section, the Group Box.
[612]
I hold down the Alt key, to make the Group Box snap to the cells.
[617]
And then, starting in the top-left corner, drag down towards the bottom-right corner.
[623]
And there’s my Group Box.
[625]
Now, I’m going to click once, on: Group Box 8, and give the Group Box the name: Term, followed by a colon.
[633]
Now, I need to add those Option Buttons.
[636]
And remember that the Option Buttons mustn’t overlap the sides of the Group Box.
[640]
And I need to add them in the correct order.
[643]
That means 5 Years first, then 10, then 15, and so on.
[648]
So: Developer, on the Ribbon: Controls: Insert.
[652]
There’s an Option Button control.
[654]
And I’ll put that just to the top-left of the Group Box.
[658]
Now, the next Option Button, in the center-top of the Group Box.
[663]
The next Option Button will go to the right-top.
[668]
The next Option Button will go to the bottom-left.
[674]
The next Option Button will go bottom-center.
[678]
And the final Option Button will go bottom-right.
[684]
Now, I’m going to test those Option Buttons, just to make sure none of them overlap the side of the Group Box.
[690]
So I’ll click on the first. That’s good.
[693]
When I click on the second, the first should extinguish. That worked well.
[698]
Three, four, five, and six.
[702]
And I can see that all of the controls are working just fine.
[706]
Now, I’m going to add the captions to the controls.
[709]
So double-right-click: 5 Years.
[714]
Double-right-click, and: 10 Years.
[719]
You can see I can’t see all of the text yet, but we’ll attend to that in a moment.
[723]
Double-right-click, and: 15 Years.
[728]
Double-right-click, and: 20 Years.
[733]
Double-right-click, and: 25 Years.
[737]
Double-right-click, and 30 Years.
[742]
Now, I’m going to resize all of the Option Button controls.
[746]
You can see that, at the moment, none of them are wide enough to show me the text within them.
[752]
So I’ll need to resize at least one of them.
[755]
I’ll double-right-click on the 25 Years Option Button.
[760]
And then, just drag the border out a little, so that I can see ‘Years’.
[765]
And then, I’ll look at the size of this Option Button control.
[769]
So I’ll right-click on the 25 Years Option Button: Format Control: Size tab.
[775]
And I can see it’s 0.22 inches high and 0.73 inches wide.
[783]
And, once again, I’ll make a careful note on a piece of paper of those sizes.
[788]
Now, I’ll select all of the Option Buttons.
[791]
To do that, I’ll hold down the Ctrl key, on the keyboard, and right-click on each, in turn.
[797]
And now, I’ve selected them all. I’ll release the Ctrl key, and right-click inside any of the selected controls.
[805]
And I’ll select: Format Object, once again, and the Size tab.
[810]
For the Height, I’ll type: 0.22 (the value that I remembered from earlier).
[817]
And for the Width, I’ll have: 0.73 (as I noted earlier).
[823]
And then, I’ll click: OK, and you can see that all of the Option Buttons are now of a reasonable size.
[830]
Now, I need to space and align the Option Buttons.
[834]
I’ll begin with the top row. I’ll double-right-click on 5 Years, hold down Ctrl, right-click on 10, and right-click on 15.
[845]
And the first thing I’m going to do, is align the tops of these three controls.
[849]
So: Drawing Tools: Format, on the Ribbon.
[852]
In the Arrange group: Align, and: Align Top.
[856]
And now, I’m going to get the spacing perfect, so that the gap between each control is exactly the same.
[863]
So: Drawing Tools: Format: Arrange: Align, once more.
[868]
And, this time: Distribute Horizontally.
[871]
Now, I need to make the three lower controls perfectly line up with the three upper controls.
[878]
So I’ll double-right-click on the 20 Years Option Button control, hold down Ctrl, on the keyboard.
[884]
And right-click on the 5 Years Option Button control: Drawing Tools: Format, tab on the Ribbon.
[892]
And in the Arrange group: Align.
[894]
And, this time, I’m going to align the lefts of the Option Button.
[898]
So I’ll click: Align Left.
[902]
This time, I want to align 15 Years and 30 Years.
[906]
And I think I want to make the lefts line up, this time. Because 30 Years is a little too far to the right.
[912]
So I’ll double-right-click on 30 Years, hold down the Ctrl key, and right-click on 15 Years.
[920]
Then: Drawing Tools: Format, on the Ribbon.
[923]
In the Arrange group: Align. And, this time: Align Left.
[928]
Now I know that my 30 Years and 20 Years Option Button controls are lined up with 15 and 5,
[936]
I can equally space and align the tops of all of the Option Button controls on the bottom row.
[943]
So double-right-click on 20 Years, hold down Ctrl, right-click on 25, right-click on 30:
[950]
Drawing Tools: Format, on the Ribbon.
[952]
In the Arrange group: Align.
[954]
First of all, I’ll align the tops, and then, I will Distribute Horizontally.
[961]
And now, the Option Button controls are perfectly spaced and perfectly aligned with each other.
[967]
Now that I’ve completed the form, I’ll delete those two graphics that I added.
[972]
And all that remains, for this lesson, is to save your work.
[976]
And I’m going to save with the new name: Mortgage Calculator-2.
[981]
And, as usual, I’ll save to the folder above my Sample Files folder.
[987]
I click the Save button, and you’ve now completed Lesson 9-1: Add Group Box and Option Button controls to a worksheet form.