Run-time error: '-2147024809 (80070057): Invalid Argument

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
563
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
All I am wanting to do is delete the first item in combobox2 based on the selection of combobox1. What am I doing wrong. Please give a thorough explanation, so I can understand. Thank you.
VBA Code:
Private Sub UserForm_Initialize()
    
    Dim ctrl As Control
    
    For Each ctrl In UserForm1.Controls
        If TypeName(ctrl) = "TextBox" Then ctrl.Value = ""
        If TypeName(ctrl) = "ComboBox" Then
            ctrl.RowSource = "Employees!A2:A" & Range("A" & Rows.Count).End(xlUp).Row
        End If
    Next
  
End Sub

VBA Code:
Private Sub ComboBox1_Change()
    With Me.ComboBox1
        If .ListIndex >= 0 Then
            .RemoveItem Me.ComboBox2.ListIndex '[B]Error occurs on this line[/B]
        End If
    End With
    
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
If you use Rowsource, you need to delete the source cell since the two are linked.
 
Upvote 0
If you use Rowsource, you need to delete the source cell since the two are linked.
Parton my vba ignorance but what is the source cell, in this case? The Rowsource is set only with VBA code and not in the "Properties -ComboBox1".
 
Upvote 0
It doesn’t matter how you set the rowsource property. The source cell is whichever one has the value you are trying to remove. Do you actually need to use Rowsource?
 
Upvote 0
The values come from the below code which populates all the comboboxes on the userform, which the user will select from.
VBA Code:
"Employees!A2:A" & Range("A" & Rows.Count).End(xlUp).Row
 
Upvote 0
I know that. ;)

What I’m asking is if you have a particular reason for using rowsource to load the data into the control? For example, if you’re using column headers.
 
Upvote 0
That's just what i saw other people do when searched the web on how to populate a combobox.
 
Upvote 0
Try using:

Code:
ctrl.List = sheets("Employees").range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row).value
 
Upvote 0

Forum statistics

Threads
1,213,550
Messages
6,114,265
Members
448,558
Latest member
aivin

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