PC Review


Reply
Thread Tools Rate Thread

ActiveSheet.ShowAllData

 
 
oldjay
Guest
Posts: n/a
 
      19th Feb 2010
This fails at the last line "ShowAllData method of worksheet class failed" if
there is no filtering active

Private Sub CommandButton1_Click() 'Clears all filters
Range("A3").Select
ActiveSheet.ShowAllData
End Sub

End Sub
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      19th Feb 2010
This is a commandbutton placed on a worksheet?

If yes:

with me
if .filtermode then
.showalldata
end if
end with

If it's a commandbutton on a userform, then using Activesheet makes sense.

oldjay wrote:
>
> This fails at the last line "ShowAllData method of worksheet class failed" if
> there is no filtering active
>
> Private Sub CommandButton1_Click() 'Clears all filters
> Range("A3").Select
> ActiveSheet.ShowAllData
> End Sub
>
> End Sub


--

Dave Peterson
 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      19th Feb 2010
Hi oldjay,

This firstly tests if filtering dropdown arrows are on then tests if a
filter is actually applied.

Private Sub CommandButton1_Click() 'Clears all filters
With ActiveSheet
If .AutoFilterMode Then
If .FilterMode Then
ActiveSheet.ShowAllData
End If
End If
End With
End Sub

--
Regards,

OssieMac


"oldjay" wrote:

> This fails at the last line "ShowAllData method of worksheet class failed" if
> there is no filtering active
>
> Private Sub CommandButton1_Click() 'Clears all filters
> Range("A3").Select
> ActiveSheet.ShowAllData
> End Sub
>
> End Sub

 
Reply With Quote
 
Ryan H
Guest
Posts: n/a
 
      19th Feb 2010
You are getting the error, because there is no data being filtered. In other
words, although AutoFilter Mode is on all rows are visible. I don't normally
use the On Error Resume Next, but this case it may make sense to use it.

By the way, you don't have to select a sheet to run your code. Just
reference your sheet by name. Put the sheet name in where I have Your Sheet
Name Here or just use the code below (which is yours).

Hope this helps! If so, let me know, click "YES" below.

Private Sub CommandButton1_Click() 'Clears all filters
On Error Resume Next
Sheets("Your Sheet Name Here").ShowAllData
On Error GoTo 0
End Sub



Private Sub CommandButton1_Click() 'Clears all filters
Range("A3").Select
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
End Sub


--
Cheers,
Ryan


"oldjay" wrote:

> This fails at the last line "ShowAllData method of worksheet class failed" if
> there is no filtering active
>
> Private Sub CommandButton1_Click() 'Clears all filters
> Range("A3").Select
> ActiveSheet.ShowAllData
> End Sub
>
> End Sub

 
Reply With Quote
 
Ryan H
Guest
Posts: n/a
 
      19th Feb 2010
I figured there was a way to test if data is filtered or not. I hate using
the On Error Goto Next statement.

Private Sub CommandButton1_Click() 'Clears all filters
With Sheets("Your Sheet Name Here")
If .AutoFilterMode And .FilterMode Then .ShowAllData
End With
End Sub

--
Cheers,
Ryan


"OssieMac" wrote:

> Hi oldjay,
>
> This firstly tests if filtering dropdown arrows are on then tests if a
> filter is actually applied.
>
> Private Sub CommandButton1_Click() 'Clears all filters
> With ActiveSheet
> If .AutoFilterMode Then
> If .FilterMode Then
> ActiveSheet.ShowAllData
> End If
> End If
> End With
> End Sub
>
> --
> Regards,
>
> OssieMac
>
>
> "oldjay" wrote:
>
> > This fails at the last line "ShowAllData method of worksheet class failed" if
> > there is no filtering active
> >
> > Private Sub CommandButton1_Click() 'Clears all filters
> > Range("A3").Select
> > ActiveSheet.ShowAllData
> > End Sub
> >
> > End Sub

 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      19th Feb 2010
That should have been just .ShowAllData. Don't need to repeat ActiveSheet in
the With / End With.

Private Sub CommandButton1_Click() 'Clears all filters
With ActiveSheet
If .AutoFilterMode Then
If .FilterMode Then
.ShowAllData
End If
End If
End With
End Sub

--
Regards,

OssieMac


 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      19th Feb 2010
Thanks for your contribution Ryan. You just forced me into testing this
because for some reason I had the idea that AutoFilterMode and FilterMode
could not be used in the one line because I was sure that FilterMode produced
an error if the filter dropdowns were not visible. However, my belief was not
correct and I have now realized that the code can be simplified even more by
just testing for FilterMode.

Private Sub CommandButton1_Click() 'Clears all filters
With ActiveSheet
If .FilterMode Then .ShowAllData
End With
End Sub

Tested in xl2002 and xl2007 and it works fine.



--
Regards,

OssieMac


"Ryan H" wrote:

> I figured there was a way to test if data is filtered or not. I hate using
> the On Error Goto Next statement.
>
> Private Sub CommandButton1_Click() 'Clears all filters
> With Sheets("Your Sheet Name Here")
> If .AutoFilterMode And .FilterMode Then .ShowAllData
> End With
> End Sub
>
> --
> Cheers,
> Ryan
>
>
> "OssieMac" wrote:
>
> > Hi oldjay,
> >
> > This firstly tests if filtering dropdown arrows are on then tests if a
> > filter is actually applied.
> >
> > Private Sub CommandButton1_Click() 'Clears all filters
> > With ActiveSheet
> > If .AutoFilterMode Then
> > If .FilterMode Then
> > ActiveSheet.ShowAllData
> > End If
> > End If
> > End With
> > End Sub
> >
> > --
> > Regards,
> >
> > OssieMac
> >
> >
> > "oldjay" wrote:
> >
> > > This fails at the last line "ShowAllData method of worksheet class failed" if
> > > there is no filtering active
> > >
> > > Private Sub CommandButton1_Click() 'Clears all filters
> > > Range("A3").Select
> > > ActiveSheet.ShowAllData
> > > End Sub
> > >
> > > End Sub

 
Reply With Quote
 
Slim Slender
Guest
Posts: n/a
 
      20th Feb 2010
All of these procedures remove filtering completely.
Is there a way to unfilter any particular column but leave the filter
controls at the top for future use.
 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      21st Feb 2010
Hi Slim,

Following shows how to test if individual filter is on and how to turn off
an individual filter. (You don't have to test if on before turning off; that
is just part of my example. However, need to test for .AutoFilterMode
otherwise the code errors if AutoFilter NOTon.).


Sub FilterTest()

With Worksheets("Sheet1")
If .AutoFilterMode Then
'Test if filter 3 is applied
If .AutoFilter.Filters(3).On Then
'Turn off filter 3
.AutoFilter.Range.AutoFilter Field:=3
End If
End If
End With
End Sub


One would think that .AutoFilter.Filters(3).On = False should work but it
doesn't and I can't find any other method other than my example to turn if
off.

--
Regards,

OssieMac


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use a password in VBA ActiveSheet.protect & ActiveSheet.unprotect? Jim K. Microsoft Excel Programming 2 2nd Jun 2008 08:09 PM
I get an error with ActiveSheet.ShowAllData =?Utf-8?B?Y3NkamowMjExOTE=?= Microsoft Excel Crashes 0 20th Sep 2006 09:22 PM
Troubles with ActiveSheet.ShowAllData bradjensmith@gmail.com Microsoft Excel Programming 3 1st Jun 2006 02:50 PM
Re: ActiveSheet.ShowAllData shows everything - way to have hidden _not_show up? Dave Peterson Microsoft Excel Programming 0 8th Jul 2004 04:33 AM
ActiveSheet.ShowAllData Paul Microsoft Excel Setup 3 10th Dec 2003 02:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:58 PM.