Combobox issues on userform to update advanced filter

rhombus4

Well-known Member
Joined
May 26, 2010
Messages
586
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Have an advanced filter which works when I edit values in my criteria on sheet1.

However when I enter values in a combobox which transfers a value to a cell in the criteria area I get errors when the advanced filter runs

Unable to get the current region property if the range Class on line
ws.cells(2, 2).currentregion.offset(1).clear contents

When I change it to ws.range("B2:F100").clear contents I get Clear contents method of range Class failed
 
What happened to the arrayfromrange function?
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Sorry I changed the names of the Comboboxes and when I reposted the Code I copied the one before the array part

This is updated which gives me an error when the Dynamic range after the Advanced Filter has no entries in that particular column

Me.cmb2.RowSource = ""
Me.cmb2.List = ArrayFromRange(Application.Range("rsCombo2")) '1004: Method Range of object Application failed if there are no entries in Dynamic Range

Also when I enter ?Application.Range("rsCombo2").address in Immediate window i get the same error
 
Upvote 0
What do you want to happen when there aren't any entries in the range?
 
Upvote 0
when the combobox dropdwon is clicked to show nothing there maybe artificially make dropdown K2 or K2:K3, thought the ArrayFromRange did that

As K1 is the heading maybe something like below unless you can think of a better way :)

If CountA(K:K) <2 then
Me.cmb2.List = "K2:K3")
Else
Me.cmb2.List = ArrayFromRange(Application.Range("rsCombo2"))
end if
 
Last edited:
Upvote 0
You could use something like:

VBA Code:
Sub Row_Sources()
On Error Resume Next
With ComboBox1
   .RowSource = ""
   .Clear
   .List = ArrayFromRange(Application.Range("rsCombo1"))
End With
With ComboBox2
   .RowSource = ""
   .Clear
   .List = ArrayFromRange(Application.Range("rsCombo2"))
end with
End Sub

or just amend the name definition so that it always returns at least one cell using MAX(1,COUNTA(...)) rather than just COUNTA(...)
 
Upvote 0
When I used code above, I entered a value in 1st ComboBox which has entries for each column in Advanced FIlter. It cleared 1st ComboBox so didn't even run the Advance Filter

If I comment out .Clear for a combobox which didn't cause issues before it populated COmbobox 2 as it should with whatever values appear in the Advanced Filter Column
But When I enter a value in Combobox 1 which maybe hasn't got any values in the Advanced Filter, the 2nd ComboBox fills up with every value even though the column is blank


I actually have 5 comboboxes, so when combo1 is changed combo 2 3 4 and 5 should be updated with whatever appears in their respective columns in the advanced filter

If no Values appear in their respectuve columns then that particular combobox will be empty
 
Upvote 0
I’d suggest you revert the code to what it was and amend the named ranges as I suggested.
 
Upvote 0
Solution
Thanks. Editing the dynamic code worked

Thought it was going to an easy job, turned out to be alot more complicated than I thought
 
Upvote 0

Forum statistics

Threads
1,214,840
Messages
6,121,895
Members
449,058
Latest member
Guy Boot

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