How to Get the First Column Value in Excel VBA ListView
Question details
The user needs to retrieve the data from the first column of a selected row in an Excel VBA ListView control.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Extracting information from a selected item within a UserForm ListView control using VBA code.
- Observed behavior
- Attempting to use ListSubItems(0) to get the first column results in a runtime error because ListSubItems only stores data for the second column onward.
Ensure your Excel Developer tab is enabled, and that you have a UserForm containing a populated ListView control ready for code modification.
Use the SelectedItem.Text Property
Access the primary text of the ListView row directly through the SelectedItem property, bypassing the ListSubItems collection for the first column.
In an Excel VBA ListView control, the first column is considered the main 'ListItem', while any subsequent columns are treated as its 'ListSubItems'.
Because the ListSubItems collection is 1-based and only begins at the second column, attempting to call ListSubItems(0) will always trigger an 'Index out of bounds' or object-defined error.
Press Alt + F11 on your keyboard to launch the Visual Basic for Applications (VBA) editor. Navigate to the code module for the UserForm containing your ListView.
Locate the event where you want to extract the data (like a button click or ListView click). Use the '.Text' property of the SelectedItem. For example, write: Selected_ID = lvwShowUserLog.SelectedItem.Text
If you also need to retrieve data from the second column or beyond, use the ListSubItems collection. The second column is accessed via: lvwShowUserLog.SelectedItem.ListSubItems(1).Text

Run VBA and Macros Seamlessly in WPS Office
WPS Spreadsheet provides excellent support for VBA macros and ActiveX controls. You can create, edit, and run your UserForms and ListView controls with the exact same syntax you use in Microsoft Excel.
- 1. Download and Install WPS Office: Install the latest version of WPS Office and ensure you have the VBA module enabled during setup.
- 2. Open your Macro-Enabled File: Launch WPS Spreadsheet and open your existing .xlsm or .xlsb workbook containing your ListView UserForm.
- 3. Access the VBA Editor: Navigate to the Developer tab on the ribbon and click 'Visual Basic' (or press Alt+F11) to view and edit your VBA code.
- 4. Run your UserForm: Execute your macro seamlessly. Your existing code using 'SelectedItem.Text' will function perfectly without any modifications.

Frequently Asked Questions
Why does ListSubItems(0) throw an 'Index out of bounds' error in VBA?
The ListSubItems collection in VBA is strictly 1-based and only accounts for columns starting from the second column. The first column is the parent ListItem itself, so an index of 0 does not exist in the sub-items collection.
How can I loop through all selected items in a multi-select VBA ListView?
You can iterate through the ListView.ListItems collection using a For Each loop. Inside the loop, check if the '.Selected' property of the current ListItem is True. If it is, you can read its '.Text' property to get the first column value.
Can I edit the first column value directly in the VBA ListView at runtime?
Yes, if the LabelEdit property of the ListView control is set to lvwManual or lvwAutomatic, users can click the first column to edit it. You can then capture or validate the new text using the AfterLabelEdit event in your VBA code.




