Solved

Remove Duplicate Values in ListBox

Posted on 2011-02-26
1
1,557 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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

631 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