Excel VBA Checkbox Function

Written by darrin koltow
  • Share
  • Tweet
  • Share
  • Email

The purpose of the checkbox control used in programs written with Visual Basic for Applications, or VBA, is to provide a means for program users to enter a "yes" or "no" reply to a question. VBA developers use several tools and methods to enable the checkbox control to fulfil this function. Excel makes these tools available in its VBA programming environment.

Other People Are Reading

Installing a Checkbox on a Userform

Developers open the Visual Basic development environment by clicking the "Visual Basic" command of Excel's "Developer" tab. In this environment, they'll create a userform to host a checkbox by clicking the "Userform" command of the "Insert" menu. Developers will drag the checkbox control from the development environment's toolbox onto the form, usually along with other controls and prompts for other user data.

Setting Attributes for Appearance

Once the checkbox is on a userform, developers will adjust the appearance and behaviour of the checkbox by using this control's "Properties" window, which they display by right-clicking the checkbox and clicking "Properties." This window lists many attributes for the checkbox, but developers typically only need to set a few of them. One is the "Caption" property, which provides a descriptive label for the checkbox. For example, a developer might write the following text in the "Caption" property of a checkbox for a question about subscription preferences: "Subscribe me to your newsletter."

Setting Properties for Programming

The developers set attributes of the checkbox that let them write programming statements for controlling the checkbox. For example, they'll set the "Name" attribute of a checkbox to something that's easy to remember and that relates to the purpose of the checkbox. For example, a developer might set the "Name" attribute of a checkbox indicating a user's subscription preference to "cbxSubscribeMe."

The Click Event Function

After setting a checkbox's attributes for its appearance and behaviour, developers write code that Excel will execute once the program's user checks or unchecks the checkbox. They write this code in an event function called "Click." An event function is one that Excel runs when a mouse click, keypress or other action happens. In the "Click" event for a checkbox indicating user subscription preferences, the developer might write code that removes or adds the user's name from a database table named "Subscribers."

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.