troubleshooting Question

How to use VBA to remove values from a Listbox

Avatar of Ed_CLP
Ed_CLP asked on
Microsoft ExcelMicrosoft Applications
3 Comments1 Solution459 ViewsLast Modified:
I am trying to remove all values from a Listbox in a Worksheet (not a Userform).
I can use this code to de-select all values, but I haven't been able to find a way to actually remove all items.  I get a "method not supported by this object" if I try to use .Clear or RowSource = ""

Sub ListClear()

    Dim ws As Worksheet
    Dim LB As MSForms.ListBox
    Dim lCount As Long
    Set ws = ActiveSheet
    Set LB = ws.OLEObjects("ListBox2").Object
    With LB
        For lCount = 0 To .ListCount - 1
           .Items(lCount) = False
    End With
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros