Solved

Remove Duplicate Values in ListBox

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

758 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now