Solved

Remove Duplicate Values in ListBox

Posted on 2011-02-26
1
1,526 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

752 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