ListBox population problem...

Matty

Well-known Member
Joined
Feb 17, 2007
Messages
3,717
Hi,

I'm using the following code to populate a ListBox:

Code:
    LR = Sheet2.Range("D" & Rows.Count).End(xlUp).Row
    
    With lbxTest
        .Clear
        For i = 1 To LR
            .AddItem Sheet2.Range("D" & i).Value
        Next i
    End With

On occasions, column D of Sheet2 will be empty. When this happens, I want my ListBox to be empty, i.e. no tick boxes.

At the moment a single tick box is added when column D is empty, so how can I prevent this from happening?

Cheers,

Matty
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi,

Thanks for the link. It looks a useful resource, but I can't see anything to handle my particular issue.

Anyone any other ideas?

Cheers,

Matty
 
Upvote 0
I'd suggest just checking D1:

Code:
    LR = Sheet2.Range("D" & Rows.Count).End(xlUp).Row
    lbxTest.Clear
    If LR > 1 then
    lbxTest.List Sheet2.Range("D1:D" & LR).Value
     Else
        if len(Sheet2.Range("D1").Value <> 0 then lbxTest.AddItem Sheet2.Range("D1").Value
    End If
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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