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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
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,945
Messages
6,122,397
Members
449,081
Latest member
JAMES KECULAH

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