VBA & Macro Problems

How to Add Multiple ListBox Rows to an Excel Worksheet with VBA

Anum MushtaqAnum Mushtaq Oct 28, 2026 870 views

Question details

The user wants to transfer multi-column data between an Excel worksheet range and a UserForm ListBox using VBA.

How to Add Multiple ListBox Rows to an Excel Worksheet Using VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
Developing a VBA UserForm that requires loading a selected range of multi-column data into a ListBox, and then copying that ListBox data back to a new worksheet.
Observed behavior
The user needs the exact VBA methods and syntax to correctly define column counts, assign arrays, and resize the target range to successfully pass data between the worksheet and the UserForm ListBox.
Before you start

Ensure the Developer tab is enabled in your Excel or WPS Spreadsheet ribbon. You will need basic familiarity with the VBA Editor (Alt + F11) and adding UserForms with ListBox controls.

Solution 1Recommended

Populate a UserForm ListBox from an Excel Range

Use this method to dynamically load a selected range of rows and columns from your worksheet into a multi-column ListBox on a UserForm.

To load multi-column data from a spreadsheet into a UserForm ListBox, you must first dynamically set the ListBox's ColumnCount property to match the selected range. You can then loop through the rows, use AddItem for the first column, and populate the remaining columns using the List property.

1
Open the VBA Editor

Press Alt + F11 to open the Visual Basic for Applications editor. Insert a new UserForm and add a ListBox (e.g., ListBox1) and a CommandButton (e.g., CommandButton1).

2
Add the VBA code

Double-click the CommandButton to open its code module. Declare your Range variables and use 'Set rng = Selection'. Count the columns using 'nCol = rng.Columns.Count' and apply it to the ListBox: 'Me.ListBox1.ColumnCount = nCol'.

3
Loop through the selection

Create a For Each loop over the first column of the selection. Use '.AddItem r.Value' to add the first column's data, and a nested loop with '.List(.ListCount - 1, x) = r.Offset(, x).Value' to fill the adjacent columns.

4
Run the UserForm

Return to your worksheet, select the data range spanning multiple columns, and trigger your UserForm. Clicking the CommandButton will instantly populate the ListBox with your selection.

Populate a UserForm ListBox from an Excel Range
Advanced Macro Support in WPS Office

Write and Run VBA Macros Easily with WPS Office

WPS Spreadsheet offers excellent support for VBA and macros, allowing you to create UserForms, manage ListBoxes, and automate your data workflows using the exact same code logic.

  1. 1. Download WPS Office: Install WPS Office for free from the official website.
  2. 2. Enable Macros: Open your macro-enabled workbook (.xlsm) in WPS Spreadsheet and enable macros when prompted.
  3. 3. Access the VBA Editor: Navigate to the Developer tab and click on 'VBA Editor' to view and modify your UserForms and code.
  4. 4. Run your Automations: Execute your ListBox data transfer scripts directly within the WPS interface.
High compatibility with Microsoft Excel VBA syntax and objectsCreate and edit UserForms with an intuitive visual editorLightweight application that runs macros quickly and efficientlySeamlessly open, edit, and save .xlsm macro-enabled workbooks
microsoft office alternative - wps office

Frequently Asked Questions

Why is my ListBox only showing one column of data?

By default, a ListBox has a ColumnCount of 1. You must explicitly set the ColumnCount property in your VBA code (e.g., ListBox1.ColumnCount = nCol) or in the Properties window to match the number of columns in your data source.

How can I export only the selected row from a ListBox to the worksheet?

Instead of exporting the entire .List array, loop through the ListBox items and check the .Selected(i) property. If it evaluates to True, write the specific row's values to the target worksheet cells.

Does this VBA code work for ActiveX ListBoxes directly on a worksheet?

The specific code provided is designed for a ListBox control placed on a UserForm. For an ActiveX ListBox embedded directly on a worksheet, the object referencing (like Me.ListBox1) and population methods will differ slightly.

How do I clear the ListBox before adding new data?

You can use the .Clear method (e.g., Me.ListBox1.Clear) before running the loop to add new items. This ensures the ListBox doesn't append the new data to the bottom of previous entries.