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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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