• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Populate listBox with range if the rows where B contains a certain value

Belleke

Well-Known Member
Hello,
I want to populate a listBox with the rows where column B contains Yes, the rest schould not be in the listbox. Column A:D
I have this code but it does not work
Code:
Private Sub CheckBox1_Click()
    Dim r As Long
    Dim m As Long
    Dim wsh As Worksheet
    Set wsh = Worksheets("Facturen")
    If CheckBox1.Value = True Then
    ListBox1.Clear
    m = wsh.Range("B" & wsh.Rows.Count).End(xlUp).Row
    For r = 2 To m
        If wsh.Range("B" & r).Value = "Yes" Then
            Me.ListBox1.AddItem wsh.Range("B" & r)
        End If
    Next r
    End If
End Sub
Please advice
 
Hi @Belleke

The way I see it, you must have one of two problems (or both :))

1) You may not have a "Checkbox1" object, so the code stops at
Code:
If CheckBox1.Value = True
To fix this delete the if condition, i.e. the following lines
Code:
If CheckBox1.Value = True Then

End If

2) You are inserting the code in a module instead of the sheet object... the code must be in Sheet "Facturen" as below:JPEG1.jpg

Hope this helps
 
Back
Top