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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
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,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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