Dependent ComboBox VBA Question

vhanus2

New Member
Joined
Aug 17, 2018
Messages
2
Afternoon everyone,

Im currently using vba to connect two comboboxes in excel.

The code is doing what it is supposed to; however, it is still giving me an error code and i cannot wrap my head around it.

Code:
Private Sub cboSupplier_Change()
Dim r As Integer
r = 2
Range("M2") = cboSupplier.Value
Columns("J:K").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
        "M1:M2"), CopyToRange:=Range("O1:P1"), Unique:=False
cboFund.Clear
Do Until Cells(r, 16).Value = ""
cboFund.AddItem Cells(r, 16).Value
r = r + 1
Loop
End Sub

I get error 1004: AdvancedFilter Method of Range class failed.

Any help on this would be greatly appreciated!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Have you tried changing:
cboFund.AddItem Cells(r, 16).Value
to:
cboFund.AddItem (Cells(r,16).value)

If that doesn't help, you may need to step through the code line by line to figure out where the error is happening.
 
Upvote 0
place the curser in the sub you want to test and press F8, this will run 1 line of the code each time you press it. When it errors out, you will know the exact line of code the problem occurs on, which can help narrow down the problem. If this sub is part of a larger set of code and running it independently like that is not an option, then in the box where the code exists, left click just to the left of the first line of code in the sub you want to test (in the little grey band next to code), this will create a red dot there (and I believe highlight that line of code in red as well). What that will do is when the code is running normally, it will automatically stop when it gets to the red dot, and then you can use F8 to step through each line of code. (just left click the red dot to remove it.)
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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