Autofilter method of range class failed

S

Scott

I have a worksheet that filtered on a cell that utilized the
validation tool and it worked fine with this code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Range
If Target.Address = "$B$2" Then
Set r = Me.AutoFilter.Range
r.AutoFilter field:=9, Criteria1:=Range("b2").Value
End If
End Sub

Now I added a combo box called ParentName and linked the cell to the
combo box. the issue I have is the code does not recognize a change in
cell B2. So I changed the code again and I get the range class failed
error.

Private Sub ParentName_Change()
Dim r As Range
Set r = Me.AutoFilter.Range
r.AutoFilter field:=9, Criteria1:=ParentName.Value
End Sub

Can someone see where I went wrong?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top