Remove item from combo box once it's been selected

nokoy

New Member
Joined
Oct 10, 2003
Messages
40
I have a user form that has a combo box that is populated by a range from a worksheet. All the data collected in the user form are then written to a worksheet called Data. What I would like to do is to exclude all the items that has been selected already. Say for example my Rowsource range contains the ff:

Oranges
apples
grapes
bananas
and so on .....

If the user has already selected and entered Oranges(in cell A1) & apples(in cell A2) to the Data worksheet it will no longer be in the dropdown list of the combo box.

Any help will be greatly appreciated.

Thanks

Nokoy
 
The Following procedures should all be placed in the userform.
These Procedures:
1:will never load any items into cbx that have already been placed on data sheet
2: never go back to source sheet for refresh of data , i.e. the items are removed from cbx list every time item is added to data sheet, without going back to source sheet.
3: Source fruit list is never deleted or modified


Private Sub UserForm_Initialize()
For Each Fruit In Range("rngFruits")
If Len(Trim(Fruit)) > 0 Then
If Not FindFruitInData(Fruit) Then cbxFruits.AddItem Fruit
End If ' not blank
Next Fruit
End Sub

Function FindFruitInData(Fruit) As Boolean
With Worksheets("Data").Cells
Set FruitLoc = .Find(Fruit, LookIn:=xlValues, Lookat:=xlWhole, MatchCase:=False)
If Not FruitLoc Is Nothing Then
FindFruitInData = True
Else
FindFruitInData = False
End If
End With
End Function


Private Sub cmdAddToData_Click()
'add fruit to Data Sheet
With Sheets("Data")
NxRw = .Cells(65536, 1).End(xlUp).Row + 1
.Cells(NxRw, 1).Value = cbxFruits.Value
End With
' Take from combo list
With UserForm1.cbxFruits
.RemoveItem .ListIndex
cbxFruits.Value = ""
End With
End Sub



ASSUMPTIONS:
1: Target Data sheet is called "Data" .. to modify do search for the word "Data" in above procedures
2: On Target sheet fruit are placed in Column 1 ( to modify change the number "1" in (65536, 1). AND NxRw, 1).
3: The source fruit list is found in a user defined range called rngFruits


This (I think) answers an unanswered post I made.
Working on modifying it for my sheet (skaters instead of fruit)

If I wanted this to work for two comoboxes, would I just do this formula twice with a new named range?
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,215,119
Messages
6,123,172
Members
449,094
Latest member
bes000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top