Consulting

Results 1 to 3 of 3

Thread: Clearing my autofilter

  1. #1
    VBAX Regular
    Joined
    Mar 2009
    Posts
    25
    Location

    Clearing my autofilter

    Hi VBA-lovers,

    I’ve got a small problem with an autofilter reset.

    Pls see below code. The problem I am having with this code is that it gives me the “runtime error 1004. Showall data method on worksheet class failed” when I press this button without any parameters in the autofilter is set. It works fine when a parameter is set.
    It’s probably very easy but I am a total noob at VBA programming.

    What I want is just to clear any possible filter parameters not deleting the autofilter itself.

    Please help me =)

    Regards
    Per

    [vba]
    Sub flooring_veiw()

    Sheets("History sheet").Select
    Columns("A:AA").Select
    Selection.EntireColumn.Hidden = False
    If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData
    ' rensar ditt gamla val
    Sheets("History sheet").Select
    Columns("J:U").Select
    Selection.EntireColumn.Hidden = True
    ActiveWindow.DisplayHorizontalScrollBar = False
    Range("A1").Select
    ActiveWindow.ScrollColumn = 1
    End Sub
    [/vba]

  2. #2
    VBAX Regular JONvdHeyden's Avatar
    Joined
    Mar 2009
    Location
    Hampshire, UK
    Posts
    75
    Location
    Hello

    ShowAllData will work if the range is currently filtered (i.e. with criteria). It will not if it is already displaying all data. Therefore I think it's ok to skip the error:

    [vba]
    On Error Resume Next '// proceed despite error //
    ActiveSheet.ShowAllData '// checking autofiltermode is not necessary //
    On Error GoTo 0 '// turn error handling back on //
    [/vba]
    Regards,
    Jon von der Heyden (Excel 2003, OS XP Pro)

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub flooring_veiw()

    Sheets("History sheet").Select
    Columns("A:AA").Hidden = False
    If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData ' rensar ditt gamla val
    Sheets("History sheet").Select
    Columns("J:U").Hidden = True
    ActiveWindow.DisplayHorizontalScrollBar = False
    Range("A1").Select
    ActiveWindow.ScrollColumn = 1
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •