Listbox missing data in 2nd column

drag1c

Board Regular
Joined
Aug 7, 2019
Messages
97
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
Hi,

I am using this part of the code to get data written in listbox, both 1st and 2nd column. Data is populated after button is pressed on form.
Do you have an idea why in listbox 2nd column is not populated, but if I do Debug.Print for 2nd column, I see the data:
Code:
With Me
Dim i As Integer
    i = 0
    For Each row In rows
        ' Check if the row is not empty
        If Trim(row) <> "" Then
                strSQL = "SELECT tbMaterials.[Description] FROM tbMaterials WHERE tbMaterials.[Material] ='" & row & "'"
                rs.Open strSQL, conn
                ' Add the non-empty row to the ListBox
                .lstSCL.AddItem row
                .lstSCL.List(i, 1) = rs("Description").Value
                rs.Close
        End If
    i = i + 1
    Next row
End With

Debug Code would we Debug.Print .lstSCL.List(i,1)

How to fix this?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Solved.... I didn't define number of columns.

Code:
.lstSCM.CountColumn = 2
 
Upvote 0
Solution

Forum statistics

Threads
1,224,828
Messages
6,181,204
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top