Excel VBA ComboBox: Important Properties

Adding a VBA ComboBox in Excel

Adding a ComboBox in Excel can be done in two ways: through an ActiveX Control or by creating a UserForm.

In this guide, we’ll focus on creating a ComboBox using a UserForm.

Follow these steps:

  • Open Visual Basic:
    • Go to the Developer tab and select Visual Basic.
    • This will open the Microsoft Visual Basic Application window.

How to Add VBA ComboBox in Excel

  • Create a UserForm:
    • From the Insert tab, choose UserForm to create a form.

    • You’ll see a UserForm and a Toolbox.
  • Add a ComboBox:
    • Select the ComboBox icon from the Toolbox and place it on the form where you want it to appear.

    • Put the icon in the place where you want to show your ComboBox.
    • Resize the ComboBox by dragging the (+) icon.

How to Add VBA ComboBox in Excel

    • We have added a ComboBox in Excel.


Dataset Overview

We will use a dataset containing the marks of a class. The dataset has information about Student ID, Student Name, and marks in Mathematics, Physics, and Chemistry. We have added a ComboBox to access the dataset.

excel vba combobox properties


Accessing the VBA ComboBox Properties

Let’s explore important properties of the VBA ComboBox:

Property 1 – Alphabetic/Categorized Menu Bar

  • Right-click on the ComboBox and select Properties.
  • In the Properties window, you’ll find two tabs:
    • Alphabetic and Categorized.
      • The Alphabetic tab lists properties in alphabetical order.

Alphabetic/Categorized Menu Bar of Excel VBA ComboBox for Properties

      • The Categorized tab groups them logically.

Alphabetic/Categorized Menu Bar of Excel VBA ComboBox for Properties


Property 2 – Naming the ComboBox

  • You can manually set the name of the ComboBox in the (Name) section.
  • For example, we’ve named ours studentinfo.

Name VBA ComboBox Using Properties Window in Excel


Property 3 – RowSource Property

  • To link the ComboBox to a cell range, use the RowSource property.
  • Specify the sheet name and cell range (e.g., Properties!B4:F14).

RowSource Properties of Excel VBA ComboBox to Access Cell Range

  • Click on the drop-down menu of the ComboBox.
  • The ComboBox will now refer to your dataset.

RowSource Property of Excel VBA ComboBox to Access Cell Range

Read More: Create ComboBox with RowSource in Excel VBA


Property 4 – Input Style

  • Explore the Style property.

Set Input Style of VBA ComboBox with Style Property in Excel

  • Choose 0-fmStyleDropDownCombo to allow manual input.
  • You can type 1606001 instead of selecting it from the drop-down menu.

Set Input Style of VBA ComboBox with Style Property in Excel

  • Choose 2-fmStyleDropDownList to restrict input to the drop-down menu.

Set Input Style of VBA ComboBox with Style Property in Excel

  • We cannot manually input data.
  • We have to select the data from the drop-down menu.


Property 5 – DropButtonStyle

  • This property controls the design of the drop-down icon.
  • There are 4 types of styles available.

DropButtonStyle Property of VBA ComboBox to Change Drop-Down Icon

  • We’ve selected DropButtonStyleEllipsis for our example.

DropButtonStyle Property of VBA ComboBox to Change Drop-Down Icon


Property 6 – ListStyle

  • There are two available styles in the ListStyle property.
  • These can be viewed by clicking on the drop-down icon in the ListStyle section.
    • Plain Style (1-fmListStylePlain): When selected, the options in the ComboBox will display a radio box icon.
    • Option Style (0-fmListStyleOption): Choosing this option hides any icons in the ComboBox options.

ListStyle Property to Change Style of ComboBox Option

  • For our example, we’ve selected the Plain Style, so the ComboBox options will show the radio box icon.

Excel VBA ComboBox Properties


Property 7 – ColumnCount

  • The ColumnCount property determines how many columns are visible within the ComboBox.
  • By default, it’s set to 1, but we’ll change it to 2.

ColumnCount Property to Increase Number of Visible Columns Inside ComboBox

  • Now, when you click the drop-down icon, you’ll see two columns of data instead of just one.
  • You can even display 3 or 4 columns by adjusting the ColumnCount value accordingly.


Property 8 – ColumnWidths

  • To adjust the width of the ComboBox, use the ColumnWidths property.
  • Since we’re working with 2 columns, set two widths—one for each column.

ColumnWidths Properties to Change Width of Excel VBA ComboBox

  • For example, we’ve set the widths as 32pt;32pt.
  • Observe the result—the ComboBox menu’s column width will decrease.
  • You can customize these widths as needed, and you can specify them in centimeters or inches.


Property 9 – BoundColumn

  • By default, it’s set to 1, meaning the ComboBox displays values from the first column.
  • Change the BoundColumn value to 2.
  • As a result, the Value property will show James.
  • This aligns with our dataset, where James is in the second column.
  • Feel free to adjust the column value based on your needs.

Update Assigned Value of ComboBox Using BoundColumn Property

Read More: Excel VBA ComboBox Value


Property 10 – TextAlign

  • The TextAlign property controls the text alignment of the ComboBox heading.
  • You can choose left, center, or right alignment.
  • For our example, we’ve selected center alignment (2-fmTextAlignCenter).

TextAlign Property to Change Alignment of VBA ComboBox

  • When you view the ComboBox, you’ll notice that “1606003” is centered.


Property 11 – Width

  • Use the Width property to modify the ComboBox’s width.
  • We’ve set it to 160.
  • Adjust this value to increase or decrease the width as desired.

Width Property for Changing ComboBox Width


Property 12 – TextColumn

  • The TextColumn property determines which column’s data appears as text in the ComboBox.
  • Typically, it’s set to 1.
  • However, we’ve set it to 2, displaying data from the second column of our initial dataset.

TextColumn Property to Update Assigned Text

  • Now, when you return to the ComboBox, it will show James.


Property 13 – BackColor

  • The BackColor property lets you choose the ComboBox’s color.
  • Use the drop-down menu to select your favorite color.

Change ComboBox Color Using BackColor Property

  • In our case, we’ve chosen a specific color, and you’ll see the ComboBox’s color change accordingly.


Property 14 – BorderColor

  • Similar to previous properties, the BorderColor property allows you to change the border color.
  • Adjust it according to your preferences.

Set Different Border Color Using BorderColor Property


Property 15 – ColumnHeads

  • By default, the ColumnHeads property is set to False.
  • However, if you set it to True, the header will appear at the top of the ComboBox options.

Access Headers of Column with ColumnHeads Property

  • Even if you didn’t explicitly select a header range from the dataset, it will still display.
  • To turn off the header, simply reset the value to False.


Property 16 – AutoSize

  • When enabled, it automatically adjusts the size of the ComboBox.
  • Instead of manually adjusting the size, set the AutoSize value to True.
  • As a result, the ComboBox will dynamically resize itself.

Fit ComboBox Size Using AutoSize Property


Property 17 – Font

  • We’ll change the font for the ComboBox:
    • Go to the Font property.
    • Click the drop-down icon to select a font.
    • We’ve chosen Times New Roman with a font size of 12.
    • Click OK to apply the changes.

Change ComboBox Font Using Font Property

  • Observe how the font and font size update in the ComboBox.


Property 18 – Enabled

  • The Enabled property determines whether the ComboBox is active.
  • By default, it’s set to True, meaning the ComboBox is enabled.
  • To disable it, set the value to False.

Enable or Disable ComboBox Utilizing Enabled Property


Property 19 – Height and Left Properties

  • Now, let’s explore the Height and Left properties:
    • Height: Adjust the height of the ComboBox as needed.
    • Left: Specify the position of the ComboBox relative to the left corner.

Change ComboBox Position with Height and Left Properties


Property 20 – ListRows

  • The ListRows property controls how many rows are visible in the ComboBox.
  • Previously, it was set to 8, displaying 8 elements.

Limit ComboBox Elements Using ListRows Property

  • We’ve changed it to 5, so now 5 rows are visible.


Property 21 – MatchRequired

  • When using the Style property (0-fmStyleDropDownComb), you can take advantage of the MatchRequired property.
  • By default, it’s set to False.
  • With MatchRequired enabled, suggestions appear as you type in the ComboBox.
  • For example, if you’re searching for Olivia, you can start typing a few letters, and the suggestions will show up.

MatchRequired Property to Maintain List Integrity


Property 22 – ShowDropButtonWhen

  • This property controls when the drop-down menu button is visible.

ShowDropButtonWhen Property to Show or Hide Drop-Down Menu

  • We’ve selected 0-ShowDropButtonWhenNever, which hides the button.
  • You can explore other options to customize its behavior.


Property 23 – SpecialEffect

  • The SpecialEffect property affects the visual appearance of the ComboBox.
  • There are five options to choose from, allowing you to customize its outlook.

SpecialEffect Property to Display Special Effects on ComboBox


Download Practice Workbook

You can download the practice workbook from here:


Related Articles

Get FREE Advanced Excel Exercises with Solutions!

Tags:

Sudipta Chandra Sarker
Sudipta Chandra Sarker

Sudipta Chandra Sarker, BSc, Electrical and Electronic Engineering, Bangladesh University of Engineering and Technology, Bangladesh, has worked on the ExcelDemy project for over a year. For ExcelDemy, he has authored 42 articles and reviewed over ten articles. He is employed as a junior software developer at the moment. He aims to create various useful Microsoft Office Add-ins, extending the functionality of Office programs. His interests span Microsoft Office Suites, Data Science, VBA, VB.NET, ASP.NET, C#, Excel, and Desktop... Read Full Bio

4 Comments
  1. Como habilito siquiero hacer una seleccion multiple del control

    • Gracias César por tu consulta. Lamentablemente, no podemos seleccionar varias opciones en un ComboBox. Sin embargo, si necesita seleccionar varias opciones, puede utilizar el ListBox que tiene la propiedad MultiSelect. Pero un inconveniente de ListBox es que no permite a los usuarios escribir directamente en él. Para obtener más información sobre MultiSelect ListBox, puede leer este artículo.
      Saludos
      Aniruddah
      Equipo Exceldemy

      [Thanks Cesar for your query. Unfortunately, we can not select multiple options in a ComboBox. However, if you need to select multiple options, you can use the ListBox that has the MultiSelect property. But, one drawback of ListBox is that it doesn’t allow the users to directly write on it. To learn more about MultiSelect ListBox, you can read this article.

      Regards
      Aniruddah
      Team Exceldemy]

  2. Great information. Regarding the rowsource data, I am trying to reference a particular column in a table of data to populate the combobox. I have gotten it to accept the table (=Sheetname!TableName) but I cannot figure out how to specify a particular column of the table. (My table has several columns)
    I have tried adding [Column] with no luck.

    • Reply Lutfor Rahman Shimanto
      Lutfor Rahman Shimanto Feb 4, 2024 at 5:51 PM

      Hello SCOTT

      Thanks a lot for your kind words. You want to specify a particular column from a table in Excel VBA ComboBox’s RowSource property.

      Output Overview:

      Let’s assume you have a table named Data in the sheet Database with several columns, and you want to populate your ComboBox with the values from a specific column, let’s say the Project column.
      You can use the following format for the RowSource property: =Database!Data[Project]

      Hopefully, the idea will help. I have also attached the solution workbook for better understanding. Good luck.

      DOWNLOAD SOLUTION WORKBOOK

      Regards
      Lutfor Rahman Shimanto
      Excel & VBA Developer
      ExcelDemy

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo