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​
 
Yes, it worked first time for me. I created a new worksheet and created a named range called People and filled that with names. Then I created a userform with two comboboxes which I fill when the form initialises:-
Code:
Private Sub UserForm_Initialize()
 
  Dim oC As Range
 
  For Each oC In Worksheets("Sheet4").Range("People")
    UserForm4.ComboBox1.AddItem oC.Value
    UserForm4.ComboBox2.AddItem oC.Value
  Next oC
 
End Sub
Then in the Change event for Combobox1, I look for and delete the same name from Combobox2:-
Code:
Private Sub ComboBox1_Change()
 
  Dim iPtr As Integer
 
  For iPtr = 0 To UserForm4.ComboBox2.ListCount - 1
    If UserForm4.ComboBox1.Value = UserForm4.ComboBox2.List(iPtr) Then
      UserForm4.ComboBox2.RemoveItem (iPtr)
      UserForm4.ComboBox2.Value = ""
      Exit For
    End If
  Next iPtr
 
End Sub
Obviously your code will be different but at least it proves it's possible.
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hello guys,

I know the post is 5 years old but I have a problem related to this, since I used the code provided here.

I have multiple comboboxes and when I select a value in one combobox it erases it from all the other. Yah :)

What I'm looking for is when you deselect it you add that item to all comboboxes again.

My (adapted) code as follows:
Code:
Sub ComboCode()

Dim i As String
Dim cbprod, tORDER, lNET, lVAT, lMIN, lTNET, lTVAT As String


i = onlyDigits(formORDER.Frame2.ActiveControl.Name)


cbprod = "cbPROD" & i
lNET = "lNET" & i
lVAT = "lVAT" & i
lMIN = "lMIN" & i
tORDER = "tORDER" & i
lTNET = "lTNET" & i
lTVAT = "lTVAT" & i


Dim cTRL, cTRL2, cTRL3 As Control


Dim c As Range


Dim pRODUCT As Range
Set pRODUCT = Sheets("PRODUCTS").Range("PRODUCTS")


Dim x, y, j As Long


Dim lNETV, lVATV, lMINV, tORDERV As Double
Dim oPERATION4, oPERATION, oPERATION2, oPERATION3 As Double


x = 0


For Each cTRL In formORDER.Frame2.Controls
    If TypeName(cTRL) = "ComboBox" And cTRL.Name = cbprod Then
            For Each cTRL2 In formORDER.Frame2.Controls
                If TypeName(cTRL2) = "ComboBox" And Not cTRL2.Name = cbprod Then
                    For j = cTRL2.ListCount - 1 To 0 Step -1   
                        If cTRL2.LIST(j) = cTRL Then cTRL2.RemoveItem (j): Exit For '<------- Yay :)
                    Next j
                End If
            Next cTRL2
    End If
Next cTRL

'the rest doesn't matter

Thanks,
João
 
Upvote 0

Forum statistics

Threads
1,216,076
Messages
6,128,669
Members
449,463
Latest member
Jojomen56

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