UserForm.ListBox Empty Header

Digitborn.com

Active Member
Joined
Apr 3, 2007
Messages
353
Hi,

I have this simple code:
Code:
    With Sheets("Sheet1")
        For Each Rw In .Range("A2:A" & .Range("A" & Rows.Count).End(xlUp).Row)
            If ComboBox1.Text = Rw.Value Then
                        ListBox1.AddItem
                        ListBox1.List(i, 0) = Rw.Offset(0, 1).Value
                        ListBox1.List(i, 1) = Rw.Offset(0, 2).Value
                        ListBox1.List(i, 2) = Rw.Offset(0, 3).Value
                        i = i + 1
            End If
        Next Rw
    End With

The problem is that I got an empty header of ListBox1 (looking like i'm using RowSource Property). This comes from the line ListBox1.AddItem. If I don't lose this line, i can't add items with ListBox.List property. How can I remove or make not appear this empty header?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Not really sure about
The problem is that I got an empty header of ListBox1 (looking like i'm using RowSource Property).

Do you have a line to initialize the variable "i" before the loop, such like i = 1 ?
If you have, just delete that line or change to i = 0

Otherwise, we will need more details about how your listbox look like....
 
Upvote 0
I don't have a line i = 0, and i don't have any other line than Dim i as Integer. The ListBox looks like you get ListBox.RowSource with an empty header.
 
Upvote 0
You can not use ColumnHeads property with AddItem method.

That is only available when you use it together with RowSorce property.
 
Upvote 0
Yes, I know that ColumnHeads are only available with RowSource, I just forgot the ColumnHeads Property in the Properties window :)
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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