PDA

View Full Version : Can't add new item to the listbox while running the userform



syed_iqbal
02-03-2017, 02:37 AM
Hi,




Pls go through the userform in attached excel file.


"Add New Genre" Code is not working.

Thank you in advance




regards
shiva

GTO
02-03-2017, 04:38 AM
Syed_iqbal,

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

Mark

syed_iqbal
02-03-2017, 05:33 AM
Hi,



Sorry, Now pls find the attached file.



regards
syed

GTO
02-03-2017, 06:30 AM
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

mike7952
02-03-2017, 07:07 AM
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