Removing autofilter by clicking a button on a userform

limeister

New Member
Joined
Feb 2, 2010
Messages
19
Hello All

I was hoping if you could help me out on an issue I am having with my autofilters.

I added the error codes below to help with the troubleshooting.

How do you get rid of / remove the autofilter?
I have a searchform that uses autofilters.

FIND ALL SECTION
Works fine. The autofilter is setup between columns B to I

Code:
Sub cmbFindAllKoreanName_Click()
    Dim strFind As String    'what to find
    Dim rFilter As Range     'range to search
    Set rFilter = Sheet10.Range("b2", Range("i65536").End(xlUp))
    Set rng = Sheet10.Range("b2", Range("b65536").End(xlUp))
    strFind = Me.txtKoreanName.Value
    With Sheet10
        If Not .AutoFilterMode Then .Range("b2", Range("i65536")).AutoFilter
        rFilter.AutoFilter field:=1, Criteria1:=strFind
        Set rng = rng.Cells.SpecialCells(xlCellTypeVisible)
        Me.ListBox1.Clear
        For Each c In rng
            With Me.ListBox1
                .AddItem c.Value
                .List(.ListCount - 1, 1) = c.Offset(0, 1).Value
                .List(.ListCount - 1, 2) = c.Offset(0, 2).Value
                .List(.ListCount - 1, 3) = c.Offset(0, 3).Value
                .List(.ListCount - 1, 4) = c.Offset(0, 4).Value
                .List(.ListCount - 1, 5) = c.Offset(0, 5).Value
                .List(.ListCount - 1, 6) = c.Offset(0, 6).Value
                .List(.ListCount - 1, 7) = c.Offset(0, 7).Value
                .List(.ListCount - 1, 8) = c.Offset(0, 8).Value
            End With
        Next c
    End With
End Sub

CLOSE FORM SECTION

I made a close button to close the form. But when I close the form I want the autofilter to be removed, vanished, no little arrows, nothing!
This is what I have.

Code:
Private Sub cmdClose_Click()
    Unload Me ' Close the current form
    frmPersonal.Show
    If Sheet10.AutoFilterMode Then Sheet10.ShowAllData
    Application.ScreenUpdating = True
End Sub


I get the following errors:

1) Run Time Error 1004
Method 'ShowAllData' of object' _Worksheet' failed

2) When I press "debug" the line of code in question is

Code:
 If Sheet10.AutoFilterMode Then Sheet10.ShowAllData

3) The autofilter is not removed. I can still see the arrows and rows are missing meaning the autofilter is still applied.


I tried the following code. It doesn't bring up the error BUT it doesn't remove the autofilter

Code:
If Sheet10.AutoFilterMode = True Then Sheet10.AutoFilsterMode = False


Your advice is desperately sought.
I tried to be as specific as possible

Thanks.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
AH!!!!
It works.

I had the order wrong? Gee I feel stupid.

Code:
Private Sub cmdClose_Click()
If Sheet10.AutoFilterMode Then Sheet10.AutoFilterMode = False
Unload Me ' Close the current form
frmPersonal.Show
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,730
Messages
6,126,528
Members
449,316
Latest member
sravya

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