How to Add Multiple ListBox Rows to an Excel Worksheet with VBA
Question details
The user wants to transfer multi-column data between an Excel worksheet range and a UserForm ListBox 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.
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.
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.
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).
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'.
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.
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.

Export ListBox Rows to a New Excel Worksheet
Use this VBA approach to bulk-copy the entire contents of a UserForm ListBox into a newly created worksheet.
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. Download WPS Office: Install WPS Office for free from the official website.
- 2. Enable Macros: Open your macro-enabled workbook (.xlsm) in WPS Spreadsheet and enable macros when prompted.
- 3. Access the VBA Editor: Navigate to the Developer tab and click on 'VBA Editor' to view and modify your UserForms and code.
- 4. Run your Automations: Execute your ListBox data transfer scripts directly within the WPS interface.

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.




