Consulting

Results 1 to 5 of 5

Thread: Can't add new item to the listbox while running the userform

  1. #1

    Can't add new item to the listbox while running the userform

    Hi,




    Pls go through the userform in attached excel file.


    "Add New Genre" Code is not working.

    Thank you in advance




    regards
    shiva
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Syed_iqbal,

    I get a red bar warning me not to open your file.

    Mark

  3. #3
    Hi,



    Sorry, Now pls find the attached file.



    regards
    syed
    Attached Files Attached Files

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Okay, you are using RowSource to populate the listbox with the (formula-driven) named range 'filmgener'. You cannot use .AddItem if you have linked the list boxes contents to a RowSource. Does that make sense?

    Mark

  5. #5
    VBAX Regular
    Joined
    Dec 2016
    Posts
    29
    Location
    Give this a try. Add the new item to sheet2 first then reassign listbox row source

    Private Sub cmdnewgenre_Click()
    Dim r As Range
        If newgenre.Value <> "" Then
            Set r = Range("a2", Range("a2").End(xlDown)).Find(newgenre.Value)
            If r Is Nothing Then
                Sheet2.Range("a2").End(xlDown).Offset(1, 0).Value = newgenre.Value
                genrelst.RowSource = "filmgener"
                newgenre.Value = ""
            End If
        End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •