Solved

Remove Duplicate Values in ListBox

Posted on 2011-02-26
1
1,453 Views
Last Modified: 2012-05-11
I have a textbox through which i populate listbox at a click f commandbutton, if i am entering duplicate value through textbox that is already in listbox, it should display a message that value already exists at specified index in listbox

EX:
If Cat is the value i am going to enter through textbox,then error should be like
"Cat" already exists at place 3 in listbox

I can enter either string or numerical or combination of both through textbox., please help me with the code to achieve the above mentioned
0
Comment
Question by:srikanthv2322
1 Comment
 
LVL 5

Accepted Solution

by:
roger_karam earned 500 total points
ID: 34987869
Hello srikanthv,

Here is a revised code for the add item button considering this.


-RK

Private Sub AddButton1_Click()

'Adds a new value to listbox2
If NewItem.Value = "" Then
MsgBox ("Please fill in value")
Exit Sub
End If

For i = 1 To ListBox2.ListCount

If NewItem.Value = ListBox2.List(i - 1) Then
MsgBox (NewItem.Value & " aleady exists at place " & i & " in list box.")
Exit Sub
End If

Next i




ListBox2.AddItem (NewItem.Value)
NewItem.Value = ""


End Sub

Open in new window

listbox-combobox-v3.xlsm
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question