Unspecified Error 80004005

mhudsora

New Member
Joined
Sep 26, 2010
Messages
10
Getting weird runtime error from code that should work:

For x = 0 To (UserForm1.ComboBox1.ListCount - 1)
If UserForm1.ComboBox1.List(x) = Userform1.ComboBox2 Then UserForm1.ComboBox1.RemoveItem (x): Exit For
Next x

Runtime error is as follows:
Excel run-time error '-2147467259(80004005)'
Unspecified error​
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Unfortunately not, the code is too vague and all help on the error just gives general statements. Hoping someone would know what is going wrong.
 
Upvote 0
Is your combobox bound to a range on your worksheet or do you populate it with VBA?
 
Upvote 0
Hi, I think you need to select something in Combobox2
Try this:-
Code:
[COLOR=navy]Sub[/COLOR] MG30Sep29
[COLOR=navy]Dim[/COLOR] x [COLOR=navy]As[/COLOR] [COLOR=navy]Integer[/COLOR]
[COLOR=navy]If[/COLOR] Me.ComboBox2.ListIndex > -1 [COLOR=navy]Then[/COLOR]
    [COLOR=navy]For[/COLOR] x = 0 To (UserForm1.ComboBox1.ListCount) - 1
        [COLOR=navy]If[/COLOR] UserForm1.ComboBox1.List(x) = UserForm1.ComboBox2 [COLOR=navy]Then[/COLOR]
            UserForm1.ComboBox1.RemoveItem (x): [COLOR=navy]Exit[/COLOR] For
        [COLOR=navy]End[/COLOR] If
    [COLOR=navy]Next[/COLOR] x
[COLOR=navy]End[/COLOR] [COLOR=navy]If[/COLOR]
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
I wasn't aware you could remove items from bound comboboxes, but I don't use Excel forms much. When I use them in Access and know I'm going to have to modify them whilst they're active, I populate them by VBA.
 
Upvote 0
Hi, I think you need to select something in Combobox2
Try this:-
Code:
[COLOR=navy]Sub[/COLOR] MG30Sep29
[COLOR=navy]Dim[/COLOR] x [COLOR=navy]As[/COLOR] [COLOR=navy]Integer[/COLOR]
[COLOR=navy]If[/COLOR] Me.ComboBox2.ListIndex > -1 [COLOR=navy]Then[/COLOR]
    [COLOR=navy]For[/COLOR] x = 0 To (UserForm1.ComboBox1.ListCount) - 1
        [COLOR=navy]If[/COLOR] UserForm1.ComboBox1.List(x) = UserForm1.ComboBox2 [COLOR=navy]Then[/COLOR]
            UserForm1.ComboBox1.RemoveItem (x): [COLOR=navy]Exit[/COLOR] For
        [COLOR=navy]End[/COLOR] If
    [COLOR=navy]Next[/COLOR] x
[COLOR=navy]End[/COLOR] [COLOR=navy]If[/COLOR]
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick

Thanks Mick for the suggestion, I did try your suggestion of selecting a value for combobox2 first and am still getting the same error. I also rewrote the code following your example but to no avail. Any other suggestions?
 
Upvote 0
I wasn't aware you could remove items from bound comboboxes, but I don't use Excel forms much. When I use them in Access and know I'm going to have to modify them whilst they're active, I populate them by VBA.

Ruddles,
If I populate through vba, should I be able to remove items from the combobox? Do I need to use an array or is there a different method?
Thanks
 
Upvote 0
Hi, The code will not work if you fill the Comboboxes wth a Rowsource/ListFillrange.
I tested the code by filling :-
Combobox1.list = Range("A1:A10").value
This worked and the Selected Item was deleted.
Mick
 
Upvote 0

Forum statistics

Threads
1,215,391
Messages
6,124,673
Members
449,178
Latest member
Emilou

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