![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
Currently having a problem removing items from a combobox. I'm trying to get my code to first of all, see if it can find a number between 1 and 30 and if it finds the number I then want to remove the number from the combobox list. Unfortunately, the remove item is removing the items in order that they are put in the box, e.g. number "1" was put into combobox first and this is given a value of "0". Is there anyway that I can remove an item from the combobox by the exact value rather than by the position that it was entered.
Any help appreciated thanks Matt Dim sec As Integer sec = 1 For sec = 1 To 30 Columns("G:G").Select Selection.Find(What:=sec, After:=ActiveCell, LookIn:=xlFormulas, LookAt _ :=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase _ :=False).Activate On Error GoTo errorhandler cboPriority.RemoveItem sec Next sec Exit Sub errorhandler: sec = sec + 1: Resume |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
|
Haven't checked this, but it should work OK: -
For x = 0 To (ComboBox1.ListCount - 1) If ComboBox1.List(x) = sec Then ComboBox1.RemoveItem x: Exit For Next x [ This Message was edited by: Mudface on 2002-05-20 05:32 ] |
|
|
|
|
|
#3 |
|
New Member
Join Date: Apr 2002
Posts: 41
|
To include your search, try something like this:
Sub out() Dim sec As Integer, f As Object, i As Integer sec = 1 With Worksheets("Sheet1").Columns("G:G") For sec = 1 To 30 Set f = .Find(What:=sec, After:=ActiveCell, LookIn:=xlFormulas, LookAt _ :=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase _ :=False) If Not f Is Nothing Then For i = UserForm1.ComboBox1.ListCount - 1 To 0 Step -1 If UserForm1.ComboBox1.List(i, 0) = sec Then UserForm1.ComboBox1.RemoveItem (i) Else End If Next i Else End If Next sec End With Exit Sub errorhandler: sec = sec + 1: Resume End Sub Any help? Regards Robb__ |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
Guys thanks, getting an error of "unable to get the find property of the range class" when using robb's suggestion. Any ideas?
thanks Matt |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
All now working, thanks for help
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|