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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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