How to Populate a VBA ListBox Using RowSource (2 Methods)

Dataset Overview

To demonstrate these methods, we’ll use a dataset of some students with their Student ID, First Name, Last Name, and Gender.

excel vba listbox rowsource

We want to show a portion of this table in a VBA Userform ListBox (for example, B4:C9).


Method 1 – Using a Named Range in the RowSource of a VBA ListBox

Steps

  • Open the Visual Basic Editor by clicking Alt+F11.

Use of Named Range in RowSource of VBA ListBox

  • Create a new UserForm by going to Insert > UserForm.

  • In the toolbox, select the ListBox icon and draw a box inside the UserForm window (named UserForm1).

Use of Named Range in RowSource of VBA ListBox

  • We will see a ListBox window named ListBox1:

Use of Named Range in RowSource of VBA ListBox

  • On the worksheet, select the range you want to display in the ListBox (e.g., B4:C9).

  • Go to the Name Box (top left corner) and give a suitable name to the selected range (e.g., Display_Text).

Use of Named Range in RowSource of VBA ListBox

  • Return to the VBA editor, left-click on ListBox1, and find the RowSource option in the Properties tab.

Use of Named Range in RowSource of VBA ListBox

  • If you scroll down in the Properties tab, you should see the RowSource option.

  • Enter the name of the range you want to display in the RowSource field.

Use of Named Range in RowSource of VBA ListBox

  • Specify the number of columns in your range (e.g., 2 for B4:C9).

Use of Named Range in RowSource of VBA ListBox

  • Save your changes.

  • Run UserForm1 to see the data displayed.

Use of Named Range in RowSource of VBA ListBox

  • You will see the form, in the main worksheet, containing the data that you have assigned using RowSource.

  • The name of the form (UserForm1) is displayed in the top left corner. It is called Caption. To change the caption, you need to change it from the Properties tab of Userform1.

Use of Named Range in RowSource of VBA ListBox


Method 2 – Using a Direct Range Reference

Steps

  • Follow the same steps as in Method 1 until you insert the data address in the RowSource box.
  • In the RowSource box, enter the following reference: 
Sheet1!B4:C9

Use of Direct Range Reference in RowSource of VBA ListBox

  • Complete the remaining steps from Method 1 to run UserForm1 with the same result.

Use of Direct Range Reference in RowSource of VBA ListBox

Read More: Create ListBox for Multiple Columns in Excel VBA


Things to Remember

  • If you don’t see the Properties tab on the left, right-click on ListBox1 and choose Properties to access it.

Download Practice Workbook

You can download the practice workbook from here:


Related Articles

Get FREE Advanced Excel Exercises with Solutions!

Tags:

Aniruddah Alam
Aniruddah Alam

Md. Aniruddah Alam, a graduate of Bangladesh University of Engineering & Technology, Dhaka, holds a BSc.Engg in Naval Architecture & Marine Engineering. Joining Softeko in August 2022 as an Excel and VBA content developer, he has authored 90+ articles, covering fundamental to advanced Excel topics. He actively develops VBA codes for Excel automation and offers solutions in the Exceldemy Forum. Beyond work, he finds leisure in reading books, and taking relaxing walks, showcasing well-rounded blend of professional and... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo