Solved

Remove Duplicate Values in ListBox

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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.
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…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

766 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